【发布时间】:2011-05-14 10:59:07
【问题描述】:
创建在模板上显示 Django 版本的 Django 模板标签的最简单方法是什么?
我想将以下内容放在 Django 模板中并让它输出 Django 版本(在我的例子中是 base.html):
{{ django_version }}
我知道下面的 Python 代码在 shell 中输出 Django 版本,但我不知道我应该把这段代码放在哪里以及我应该如何从模板中调用它:
import django
print django.VERSION
更新:我在views.py中尝试了以下内容,但模板中没有显示任何内容:
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} )
【问题讨论】:
标签: python django templates tags