简体   繁体   English

django模板上下文处理器设置在Django 1.10中的哪里放置

[英]Where do I put my django Template Context Processor setting in Django 1.10

I'm trying to migrate an old project over from Django 1.6 to 1.10. 我正在尝试将旧项目从Django 1.6迁移到1.10。

I have read the documentation but I am still having trouble understand how to handle Templates in my settings.py 我已经阅读了文档,但是仍然无法理解如何在settings.py中处理模板

In my old settings I had: 在我的旧设置中,我有:

TEMPLATE_CONTEXT_PROCESSORS = [
    "django.contrib.auth.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.core.context_processors.static",
    "django.core.context_processors.tz",
    "django.core.context_processors.request",
    "django.contrib.messages.context_processors.messages",

]

How do I migrate this over to 1.10? 如何将其迁移到1.10? Can I add it to the following? 我可以将其添加到以下内容吗?

TEMPLATES = [{
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(PACKAGE_ROOT, 'templates')],
}]

Currently when I run my Django project in 1.10, I get an error that says TEMPLATE_* settings were deprecated in Django 1.8 当前,当我在1.10中运行Django项目时,出现错误,提示TEMPLATE_ *设置在Django 1.8中已弃用

Now your template option should look like this: 现在,您的模板选项应如下所示:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
                        os.path.join(BASE_DIR, 'templates'),
                ],
        'APP_DIRS': True,
        'OPTIONS': {
            'debug': DEBUG,
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM