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, in situations when an error is raised because the template to include does not exist, rendering will outright fail. 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
3.144.46.141