March 2020
Intermediate to advanced
608 pages
17h 17m
English
An advanced custom template tag consists of a function that parses the arguments that are passed to the tag, and the Node class that renders the output of the tag or modifies the template context. Perform the following steps to create the {% load_objects %} template tag:
# myproject/apps/core/templatetags/utility_tags.pyfrom django import templatefrom django.apps import appsregister = template.Library()""" TAGS """@register.tagdef load_objects(parser, token): """ Gets a queryset of objects of the model specified by app and model names Usage: {% load_objects [<manager>.]<method> from <app_name>.<model_name> [limit <amount>] ...