Last active
August 29, 2015 13:57
-
-
Save gridcell/9476974 to your computer and use it in GitHub Desktop.
Django template tag to include template contents verbatim
This file contains hidden or 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
import os | |
from django import template | |
from django.template.loader import get_template | |
from django.conf import settings | |
register = template.Library() | |
@register.simple_tag() | |
def verbatim_include(name): | |
""" | |
Example: {% verbatim_include "persons/edit.html" %} | |
""" | |
for d in settings.TEMPLATE_DIRS: | |
pth = os.path.join(d, name) | |
if os.path.exists(pth): | |
f = file(pth, "rb") | |
return f.read() | |
raise template.TemplateDoesNotExist(name) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment