Django表2:错误django.template.context_processors.request [英] Django tables 2: error django.template.context_processors.request

查看:53
本文介绍了Django表2:错误django.template.context_processors.request的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了模块表2,然后遇到下一个问题:

I installed the module tables 2 and i have the next problem:

异常值:标记{%querystring%}需要django.template.context_processors.request必须在模板中在settings.TEMPLATES [] OPTIONS.context_processors中进行配置以便使所包含的模板标签正常运行.

Exception Value: Tag {% querystring %} requires django.template.context_processors.request to be in the template configuration in settings.TEMPLATES[]OPTIONS.context_processors) in order for the included template tags to function correctly.

我的代码是:

Settings.py

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

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>

有什么建议吗?

谢谢!

推荐答案

不再建议使用 render_to_response 快捷方式.

The render_to_response shortcut is not recommended any more.

改为使用 render 快捷方式,以便使用上下文处理器.

Use the render shortcut instead, so that the context processors are used.

return render(request, 'inicio.html', {'llamadas': llamadas})

这篇关于Django表2:错误django.template.context_processors.request的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆