我安装了模块表2,下一个问题是:
异常值:标记{% querystring %}要求settings.TEMPLATES[]OPTIONS.context_processors)中的模板配置中有django.template.context_processors.request,以便所包含的模板标记能够正常工作。
我的代码是:
Settings.py
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR + '/llamadas/plantillas')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.core.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.request',
],
},
},
]Views.py
def home(request):
if request.user.is_authenticated():
llamadas = CallEntry.objects.all()
return render_to_response('inicio.html', {'llamadas': llamadas})
else:
return HttpResponseRedirect('/accounts/login/')Inicio.html
{% load render_table from django_tables2 %}
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="{{ STATIC_URL }}django_tables2/themes/paleblue/css/screen.css" />
</head>
<body>
{% render_table llamadas %}
</body>
</html>有什么建议吗?
谢谢!
发布于 2016-05-20 13:58:33
不再建议使用render_to_response快捷方式。
改用render快捷方式,以便使用上下文处理器。
return render(request, 'inicio.html', {'llamadas': llamadas})发布于 2016-05-20 14:00:34
在您的设置中有两个context_processors.request:
'django.core.context_processors.request',
'django.template.context_processors.request',
也许只有一个是必要的。
在我的项目中,我只使用:'django.core.context_processors.request',,但是模板中的变量,即您的llamadas,是一个TableReport类型的对象。
https://stackoverflow.com/questions/37348430
复制相似问题