Skip to content

Instantly share code, notes, and snippets.

@gridcell
Last active August 29, 2015 13:57
Show Gist options
  • Save gridcell/9476974 to your computer and use it in GitHub Desktop.
Save gridcell/9476974 to your computer and use it in GitHub Desktop.
Django template tag to include template contents verbatim
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