django:ImportError:没有名为context_processors的模块

时间:2017-02-21 21:18:07

标签: django

我有一个经常出现此错误的django 1.9部署:

Internal Server Error: 
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 174, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 172, in get_response
    response = response.render()
  File "/usr/lib/python2.7/site-packages/django/template/response.py", line 160, in render
    self.content = self.rendered_content
  File "/usr/lib/python2.7/site-packages/django/template/response.py", line 137, in rendered_content
    content = template.render(context, self._request)
  File "/usr/lib/python2.7/site-packages/django/template/backends/django.py", line 95, in render
    return self.template.render(context)
  File "/usr/lib/python2.7/site-packages/django/template/base.py", line 204, in render
    with context.bind_template(self):
  File "/usr/lib64/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/usr/lib/python2.7/site-packages/django/template/context.py", line 256, in bind_template
    processors = (template.engine.template_context_processors +
  File "/usr/lib/python2.7/site-packages/django/utils/functional.py", line 33, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/lib/python2.7/site-packages/django/template/engine.py", line 105, in template_context_processors
    return tuple(import_string(path) for path in context_processors)
  File "/usr/lib/python2.7/site-packages/django/template/engine.py", line 105, in <genexpr>
    return tuple(import_string(path) for path in context_processors)
  File "/usr/lib/python2.7/site-packages/django/utils/module_loading.py", line 20, in import_string
    module = import_module(module_path)
  File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named context_processors

这是我的模板列表:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'motor/ui/templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'context_processors.config',
                'ui.context_processors.navigation',
                'core.appmngr.context_processor',
            ],
        },
    },
]

我的MIDDLEWARE_CLASSES:

MIDDLEWARE_CLASSES = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'middleware.LastSiteUrl',
]

只有这一个网站出现这些错误,我在多个网站上部署了相同的系统。我已经验证所有引用的上下文处理器和中间件都存在。我能看到什么来追踪这个?

1 个答案:

答案 0 :(得分:0)

如上所示

更改core.appmngr.context_processor, context_processors已从核心移动到模板。

'template.appmngr.context_processor', 

这可能适合你。阅读更多here