Skip to content

Instantly share code, notes, and snippets.

@tbaxter-18f
Created June 14, 2018 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbaxter-18f/ff92e03a4b97dc4fa8e7775b3707aba7 to your computer and use it in GitHub Desktop.
Save tbaxter-18f/ff92e03a4b97dc4fa8e7775b3707aba7 to your computer and use it in GitHub Desktop.
from django import template
from django.template.loader import get_template
register = template.Library()
@register.inclusion_tag('my_template_for_this_tag.html')
def show_template(template_name):
"""
Shows the output of a given template.
Usage:
{% show_template 'my.html' %}
"""
html = get_template(template_name)
return {'html': html}
====================================================================
my_template_for_this_tag.html:
<h4>Here is the template source</h4>
<pre>
{% autoescape off %}
{{ html }}
{% autoescape on %}
</pre>
<h4>And it renders as...</h4>
{{ html }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment