How it works...

Steps 2 and 4 in the How to do it… section are very straightforward: they read the template and  save the resulting report.

As seen in Steps 3 and 4, the main task is to create a context dictionary with the information to be displayed. The template then renders that information, as shown in step 5. Let's take a look at jinja_template.html:

<!DOCTYPE html>
<html lang="en">
<head>
<title> Movies Report</title>
</head>
<body>
<h1>Movies Report</h1>
<p>Date {{date}}</p>
<p>Movies seen in the last 30 days: {{movies|length}}</p>
<ol>
{% for movie in movies %}
<li>{{movie}}</li>
{% endfor %}
</ol>
<p>Total minutes: {{total_minutes}} </p>
</body>
</html>

Most of it is replacing the context values as defined between curly brackets, such as {{total_minutes}}

Note the tag, {% for ... %} / {% endfor %}, which defines a loop. That allows a very Python-based assignment to generate multiple rows or elements.

Filters can be applied to the variables to modify them. In this case, the length filter is applied to the movies list to obtain the size using the pipe symbol, as shown in {{movies|length}}.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.104.181