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}
  • >
  • {% for choice in choices %}
  • {{ choice }}
  • {% endfor %}
register.inclusion_tag('results.html')(show_results)   # Here register is a django.template.Library instance.
{% show_results poll %}
  • First choice
  • Second choice

The article was originally published at MicroPyramid blog.

--

--

--

Python, Django, Android and IOS, reactjs, react-native, AWS, Salesforce consulting & development company

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Four Faith Industrial routers Command Injection RCE Reverse Shell

101 AWS Lambda

Safely Install Spark and Use in Python and Jupyter on Windows

5 useful websites for web developers

Scoped storage in Android 11

jenkins housekeeping

The Modern Day Computer Engineering.

Finding the Maximum Accessible Area on a 2D Grid

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
MicroPyramid

MicroPyramid

Python, Django, Android and IOS, reactjs, react-native, AWS, Salesforce consulting & development company

More from Medium

Docker zing a Python Django Web App on Ubuntu

Change rest_framework’s request parameter validation failure response

All about Views in Django REST Framework(DRF) — GenericAPIView and Mixins

Introduction to Django Framework

introduction to Django Framework