I am using flask. I have a url such as: http://example.com/page/page_id
I want to know how to get the page_id
part from url in the route. I am hoping I could devise some method such as:
@route('/page/page_id') def page(page_id): pageid = page_id
In the first one we would use request. args. get('<argument name>') where request is the instance of the class request imported from Flask. Args is the module under which the module GET is present which will enable the retrieve of the parameters.
App routing is used to map the specific URL with the associated function that is intended to perform some task. It is used to access some particular page like Flask Tutorial in the web application.
The url_for() function is very useful for dynamically building a URL for a specific function. The function accepts the name of a function as first argument, and one or more keyword arguments, each corresponding to the variable part of URL.
It's pretty straightforward - pass the path parameter in between angle brackets, but be sure to pass that name to your method.
@app.route('/page/<page_id>') def page(page_id): pageid = page_id # You might want to return some sort of response...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With