Issue
How can I retrieve a request param a
in Jinja2 template?
http://foo.bar?a=1
Solution
I'm a bit late with this answer, but the other solutions don't really account for your use of Flask.
The fact that you're using Flask with Jinja2 makes your situation a bit different from other frameworks. Flask actually makes some global variables available to you in all Jinja2 templates without requiring you to pass them to the template explicitly.
To quote a part of the Flask documentation at http://flask.pocoo.org/docs/templating/#standard-context:
The following global variables are available within Jinja2 templates by default:
...
request The current request object (flask.request)
...
So for example to show the request parameter 'a' in the template:
{{ request.args.get('a') }}
The documentation link also lists the other global variables you can access in a similar way.
Answered By - Kalle
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.