Django Template tags code example
Example 1: use django taggit in template
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()
{% 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()
@register.simple_tag
def fun_name(data):
return data
Example 3: django url template
Django URL Mapping
Example 4: template tag django
if create_time >= last_date:
Example 5: django html templates
Django templates folder