您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Django:重新启动后出现“ No module named context_processors”错误

Django:重新启动后出现“ No module named context_processors”错误

问题是升级到Django 1.8后,在settings.py中没有按要求设置模板设置。我还不清楚为什么它可以在使用Django服务器的PC上运行。

从allauth文档中,我将其粘贴到设置文件中:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                # Already defined Django-related contexts here

                # `allauth` needs this from django
                'django.template.context_processors.request',
            ],
        },
    },
]

并将我的旧TEMPLATE_DIRS设置的内容复制到TEMPLATES的DIRS定义中。最终结果如下所示:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                # Already defined Django-related contexts here

                # `allauth` needs this from django
                'django.template.context_processors.request',
            ],
        },
    },
]

根据最近的allauth更新的文档,context_processors现在需要在TEMPLATES设置中指定而不是在TEMPLATE_CONTEXT_PROCESSORS设置中。

Go 2022/1/1 18:44:13 有373人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶