In flask, you can define path parameters like so:
@app.route('/data/<section>') def data(section): print section In The above example, you can access the section variable only from the data endpoint (unless you pass it around in function parameter)
You can also get the query parameters by accessing the request object. this works from the endpoint function as well as any other called function, without needing to pass anything around
request.args['param_name'] my question is: is in possible to access the path parameter (like section above) in the same way as the query parameters?
21 Answer
It's possible to use request.view_args. The documentation defines it this way:
A dict of view arguments that matched the request.
Here's an example:
@app.route("/data/<section>") def data(section): assert section == request.view_args['section'] 2