Skip to content

Instantly share code, notes, and snippets.

@agamdua
Created May 1, 2014 13:36
Show Gist options
  • Save agamdua/b2ce859a6acec34454fd to your computer and use it in GitHub Desktop.
Save agamdua/b2ce859a6acec34454fd to your computer and use it in GitHub Desktop.
Template class from base.py in Django
class Template(object):
def __init__(self, template_string, origin=None, name=None):
try:
template_string = force_text(template_string)
except UnicodeDecodeError:
raise TemplateEncodingError("Templates can only be constructed "
"from unicode or UTF-8 strings.")
if settings.TEMPLATE_DEBUG and origin is None:
origin = StringOrigin(template_string)
self.nodelist = compile_string(template_string, origin)
self.name = name
self.origin = origin
# the rest is left out for conciseness.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment