O'Reilly logo

Django Unleashed by Andrew Pinkham

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4.5.3 Adding Logic with Template Tags

To iterate and print the lists of startups and blog posts associated with a Tag object, we need something a little more powerful than simple variables. We need a loop.

Just as Django allows for variables through the {{ }} delimiters, Django provides template tags, which are delimited by {% %}. Template tags allow for conditional logic, loops, and evaluation of functions and methods, meaning that we can run and evaluate Python in our template.

Info

On top of the {{ variable }} and {% expression %} delimiters, Django supplies {# #}, which is used to write comments in templates. The utility of using template comments over markup-specific comments is that they will not appear in the output of the rendered templates. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required