Flask Framework Cookbook(Second Edition)
上QQ阅读APP看书,第一时间看更新

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.