Django provides the following helper functions that allow you to create your own template tags in an easy manner:
- simple_tag: Processes the data and returns a string
- inclusion_tag: Processes the data and returns a rendered template
Template tags must live inside Django applications.
Inside your blog application directory, create a new directory, name it templatetags, and add an empty __init__.py file to it. Create another file in the same folder and name it blog_tags.py. The file structure of the blog application should look like the following:
blog/ __init__.py models.py ... templatetags/ __init__.py blog_tags.py
The way you name the file is important. You will use the name of this module to load tags in templates. ...