Inclusion Tags

polls/
|- __init__.py
|- models.py
|- templatetags/
|- __init__.py
|- poll_extras.py
|- urls.py
|- views.py
from django import template
register = template.Library()

Inclusion tags:

def show_results(poll):
choices = poll.choice_set.all()
return {'choices': choices}
register.inclusion_tag('results.html')(show_results)   # Here register is a django.template.Library instance.
{% show_results poll %}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store