Chapter 8. Using Built-in Template Tags to Enhance Views

What You’ll Learn in This Hour

  • loops to generate HTML code from lists
  • How to use if logic to add conditional HTML code to templates
  • How to add dynamic links to templates
  • How to reduce template code by using the with tag
  • How to add cycling behavior to enhance table views

Django has several tags that allow you to implement some basic logic in your templates that helps you reduce the amount of HTML code that you need to write. This hour covers using Django’s built-in template tags to create more complex and useful templates.

Implementing Loops

One of the most common tags that you will use will be the for tag to implement for loops inside your HTML documents. The for tag allows you to navigate ...

Get Sams Teach Yourself Django in 24 Hours 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.