django with template tag code example

Example 1: use django taggit in template

# models.py

from django.db import models
from taggit.managers import TaggableManager

class MyObject(models.Model):
    title = models.CharField(max_length=100)
    content = models.TextField()

    tags = TaggableManager()

#template.html

{% for object in objects %}
    <h2>{{ object.title }}</h2>
    <p>{{ object.content }}</p>
    <ul>
        {% for tag in object.tags.all %}
            <li> {{ tag.name }} </li>
        {% endfor %}
    </ul>
{% endfor %}

Example 2: template tags in django

from django import template

register = template.Library()

#simle Tag
@register.simple_tag
def fun_name(data):
	return data

Example 3: django html templates

Django templates folder