Created
June 14, 2018 16:14
-
-
Save tbaxter-18f/ff92e03a4b97dc4fa8e7775b3707aba7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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