Skip to content

Instantly share code, notes, and snippets.

@atmb4u
Created September 24, 2015 04:30
Show Gist options
  • Save atmb4u/ebab278291d5558a39e6 to your computer and use it in GitHub Desktop.
Save atmb4u/ebab278291d5558a39e6 to your computer and use it in GitHub Desktop.
version info for django projects with git
#add this to your urls file
url(r'^version/$', 'api.views.code_version', name='code_version'),
#add this view to your views.py file
def code_version(request):
"""
:param request: django request
:return: returns total commit counts as version
"""
try:
commit_count = int(
subprocess.Popen("git rev-list HEAD --count",
shell=True, stdout=subprocess.PIPE).stdout.read())
return HttpResponse("v%s" % commit_count)
except:
return HttpResponse("None")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment