Created
July 9, 2014 09:54
-
-
Save sveetch/95fe6137232410059300 to your computer and use it in GitHub Desktop.
Get template file last modification
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
import os, datetime | |
from django.conf import settings | |
from django.template.base import TemplateDoesNotExist | |
from django.template.loader import find_template_loader | |
def get_template_lastmod_date(template_name): | |
""" | |
Get the last modification time of the used template, this probably work only | |
with filesystem and apps template loaders | |
""" | |
for item in settings.TEMPLATE_LOADERS: | |
current_loader = find_template_loader(item) | |
if current_loader.is_usable: | |
try: | |
template, origin = current_loader.load_template_source(template_name) | |
if origin: | |
#print "Finded template:", origin | |
return datetime.datetime.fromtimestamp(os.path.getmtime(origin)) | |
except TemplateDoesNotExist: | |
pass | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment