Django template template for displaying a version of Django

What is the easiest way to create a Django template tag that displays the version of Django in the template?

I want to put the following in a Django template and release a version of Django (in my case, base.html):

{{ django_version }}

I know that the following Python code outputs a version of Django in a shell, but I'm confused about where I should put this code and how I should call it from a template:

import django
print django.VERSION

UPDATE: I tried the following in views.py but nothing is displayed in the template:

import django    
from django.template import loader, Context
from django.http import HttpResponse
from django.shortcuts import render_to_response

    def base(request):
        django_version = django.VERSION
        return render_to_response('base.html', {'django_version': django_version} )
+5
source share
3 answers

( Django 1.3) - django_version TEMPLATE_CONTEXT_PROCESSORS settings.py:

TEMPLATE_CONTEXT_PROCESSORS = (  
    # ...  
    'myproject.context_processors.django_version',  
)

context_processors.py ( zsquare):

import django
def django_version(request):
    return { 'django_version': django.VERSION }

urls.py

urlpatterns += patterns('django.views.generic.simple',
    (r'^$', 'direct_to_template', {'template': 'base.html'}),
)

: base.html:

{{ django_version }}
+3

,

context_processors.py

import django
def django_version(request):
    return { 'django_version': django.VERSION }

TEMPLATE_CONTEXT_PROCESSORS

+3

django.VERSION . django django docs, , .

+2

All Articles