Template tags
Template tags are a powerful feature of Django’s templating engine. They allow developers to build powerful templates by generating HTML by evaluating 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 the previous section:
{% load explode_filter %}
This uses a template tag known as load
, responsible for loading the explode
filter into the template. Template tags are much more powerful compared to filters. While filters have access only to the values they are operating...