Skip to content

Instantly share code, notes, and snippets.

@bryanchow
Last active July 31, 2022 23:52
Show Gist options
  • Save bryanchow/fb34d7c52d68692b23a26698e5a4ea41 to your computer and use it in GitHub Desktop.
Save bryanchow/fb34d7c52d68692b23a26698e5a4ea41 to your computer and use it in GitHub Desktop.
# https://gist.github.com/bryanchow/fb34d7c52d68692b23a26698e5a4ea41
from django.template.engine import Engine
from django.template.loaders.filesystem import Loader
def get_template_source(template_name, dirs=[]):
"""
Return the raw source code of an unrendered Django template.
"""
loader = Loader(Engine(), dirs=dirs)
template = loader.get_template(template_name)
return template.source
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment