How to Display Django version numbers in template

by Emmanuel D. on November 10, 2010

If you are using a template in Django and you want to show what version of Django you are using in your website, like the new Django 1.3, you can use this code:

In the ile context_processors.py

add this code:
import sys

import django

def DjangoVersionContextProcessor(request):

    one, two, three, four, five = django.VERSION

    return {“DJANGO_VERSION”: “%s.%s.%s” % (one, two, three)}

def PythonVersionContextProcessor(request):

    one, two, three, four, five = sys.version_info

    return {“PYTHON_VERSION”: “%s.%s.%s” % (one, two, three)}



After that, add this code in
TEMPLATE_CONTEXT_PROCESSORS tuple in settings.py file

TEMPLATE_CONTEXT_PROCESSORS = (

    … others values in tuple removed  …

    “core.context_processors.DjangoVersionContextProcessor”,
    “core.context_processors.PythonVersionContextProcessor”,
)



then add also this:

<a href=”http://python.org” title=”Python {{ PYTHON_VERSION }}”>Python {{ PYTHON_VERSION }}</a>
<a href=”http://www.djangoproject.com” title=”Django {{ DJANGO_VERSION }}”>Django {{ DJANGO_VERSION }}</a>

Here is a sample output:

Previous post:

Next post:

About |  Contact |  Sitemap |  Terms of Service |  Privacy