I’m using this Django context processor for automatically appending a query string for file cache versioning. It generates the query string off of the git revision and saves me many headaches.
from django.conf import settings
from git import Repo
import hashlib, os
git_head = Repo(settings.PROJECT_DIR).heads[0].commit.hexsha
salted_git_head = hashlib.sha512("".join([
git_head,
os.getlogin(),
"".join(os.uname()),
])).hexdigest()[0:6]
def git_head(request):
return {
"GIT_HEAD": git_head,
"SALTED_GIT_HEAD": salted_git_head,
"SALTED_GIT_QS": "v=%s" % salted_git_head,
}