Creating a template tag to include a template, if it exists

Django provides the {% include %} template tag that allows one template to render and include another template. However, this template tag raises an error if you try to include a template that doesn't exist in the filesystem. In this recipe, we will create a {% try_to_include %} template tag that includes another template, if it exists, and fails silently by rendering as an empty string otherwise.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.140.108