python - Get variable from url in view -
i want make http request ip:port/this1234
, use "1234" variable in python code. "1234" arbitrary int. how int argument view?
@app.route('/stop####') def stop####(): global stopped if stopped: call(["./stop.sh"], shell = true) stopped = false return "started" return "already started"
you'll want take @ quickstart guide.
meanwhile, can post data using
myvar = request.form["myvar"]
and using
myvar = request.args.get("myvar")
the guide goes on mention error handling recommendations , references more in depth request object page.
we recommend accessing url parameters or catching keyerror because users might change url , presenting them 400 bad request page in case not user friendly.
for full list of methods , attributes of request object, head on request documentation.
you might want @ routing bit. i'm uncertain you're trying accomplish pound sign in routing (edit: see mean on re-reading; see edit @ bottom). note quote below comment on sitepoint.
browsers don't send
#whatever
part of url server in http request when requesting page
ok, if want pass value in uri, recommend more like: example.com/this/1234
, routing rule @app.route('/this/<myvar>')
above def my_func(myvar):
finally, @ level, killing process based off of http request seems awful daring, know environment best, , know, might not exposed internet. goodluck, , don't forget safe this.
Comments
Post a Comment