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. ...

Get Django Unleashed 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.