Skip to content

Instantly share code, notes, and snippets.

@sveetch
Created July 9, 2014 09:54
Show Gist options
  • Save sveetch/95fe6137232410059300 to your computer and use it in GitHub Desktop.
Save sveetch/95fe6137232410059300 to your computer and use it in GitHub Desktop.
Get template file last modification
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