Integrating variables in templates

In our controller, we send a variable named my_var. We can display it in a <span> tag in the following way. Add the following lines in the <article> tag of our template tag:

<span> {{my_var}} </ span> 

In this way, because our variable contains string = "Hello World!", the HTML code that will be generated is as follows:

<span> Hello World! </span>

We will learn how to create conditions for variables or functions in order to filter the data in the variables in the following examples.

Conditional statements

Language templates also allow conditional structures. Note that for a display variable, double brackets {{}} are used, but once we have an action to be made as a condition or loop, we will use {%%}.

Our controller ...

Get Django: Web Development with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.