Template Tags
Template tags are a powerful feature of Django's templating engine. They allow developers to build powerful templates by generating HTML through the evaluation of certain conditions and help avoid the repetitive writing of common code.
One example where we may use template tags is the sign up/login options in the navigation bar of a website. In this case, we can use template tags to evaluate whether the visitor on the current page is logged in. Based on that, we can render either a profile banner or a sign up/login banner.
Tags are also a common occurrence while developing templates. For example, consider the following line of code, which we used to import the custom filters inside our templates in Exercise 11.01, Creating a Custom Template Filter:
{% load explode_filter %}
This uses a template tag known as load
, which is responsible for loading the explode
filter into the template. Template tags are much more powerful compared to filters. While filters...