Django表2:错误Django.template.context_处理器.需求

2024-04-26 14:43:41 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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.

我的代码是:

在设置.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',
            ],
        },
    },
]

在视图.py在

^{pr2}$

在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>

有什么建议吗?在

谢谢!在


Tags: thetodjangoinpyrequesthtmlcontext
2条回答

有两个上下文_处理器.请求在您的设置中:

'django.core.context_处理器.请求',

'django.template.context_处理器.请求',

也许只有一个是必要的。。。在

在我的一个项目中,我只使用:'django.core.context_处理器。请求',但模板中的变量,即llamadas,是TableReport类型的对象。在

不再建议使用render_to_response快捷方式。在

请改用render快捷方式,以便使用上下文处理器。在

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

相关问题 更多 >