我已经将Django从版本1.8升级到了1.10版本,现在我得到了以下错误:
No module named context_processors这与settings.py中的代码有关。如果我注释掉以'django.core开头的行,它运行得很好,但我显然会失去功能:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
TEMPLATE_PATH,
],
'APP_DIRS': True,
'OPTIONS': {
'debug': DEBUG,
'context_processors': [
...
'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.contrib.messages.context_processors.messages',
...
],
},
},
]我怎么才能解决这个问题?
发布于 2017-01-30 22:33:19
经过大量的挖掘,我找到了一个解决办法。隐藏在文献资料中的是该问题的解决方案:
django.core.context_processors 内置的模板上下文处理器已经转移到django.template.context_processors中。
因此,为了解决这个问题,您需要用django.core替换django.template。然后,代码将如下所示:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
TEMPLATE_PATH,
],
'APP_DIRS': True,
'OPTIONS': {
'debug': DEBUG,
'context_processors': [
...
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
...
],
},
},
]https://stackoverflow.com/questions/41946604
复制相似问题