- Flask Framework Cookbook(Second Edition)
- Shalabh Aggarwal
- 140字
- 2021-06-24 13:58:01
How it works...
Now, if we open the http://127.0.0.1:5000/hello URL in a browser, we should see a response similar to the one shown in the following screenshot:
If we pass a URL argument with the user key as http://127.0.0.1:5000/hello?user=John, we should see the following response:
As we can see in views.py, the argument passed in the URL is fetched from the request object using request.args.get('user') and then passed to the context of the template being rendered using render_template. The argument is then parsed using the Jinja2 placeholder, {{ user }}, to fetch the contents from the current value of the user variable from the template context. This placeholder evaluates all of the expressions placed inside it, depending on the template context.
The Jinja2 documentation can be found at http://jinja.pocoo.org/. This will come in handy when writing templates.