Getting a request parameter in Jinja2

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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)