March 2020
Intermediate to advanced
608 pages
17h 17m
English
For these template tags, we will be using the @simple_tag decorator that parses the components and requires you to just define the rendering function, as follows:
# myproject/apps/core/templatetags/utility_tags.pyfrom urllib.parse import urlencodefrom django import templatefrom django.utils.encoding import force_strfrom django.utils.safestring import mark_saferegister = template.Library()""" TAGS """def construct_query_string(context, query_params): # empty values will be removed query_string = context["request"].path if len(query_params): encoded_params = urlencode([ (key, force_str(value)) for (key, value) in query_params ...
Read now
Unlock full access