我有一个Django站点,它可以在我的PC上工作,并且在加载后可以在我的服务器上短暂地工作。我注意到我的服务器有Django 1.6,我升级到了1.8。
重新启动后,网站上的任何页面都不会加载,我将收到错误消息:
ImportError No module named context_processors
我通读了关于Django和allauth的文档。Django提到在1.8中,上下文处理器被移动,allauth说在TEMPLATE_CONTEXT_PROCESSORS
的settings.py
中不再需要特定的allauth标记。
Django:https://docs.djangoproject.com/en/1.8/ref/settings/
阿劳思:https://django-allauth.readthedocs.org/en/latest/installation.html
还有人碰到这个吗?我走对了吗?我需要在设置中更改一些内容吗?我真的不知道是Django还是allauth的问题,所以不知道从哪里开始。
感谢您的帮助!
回溯:
Django Version: 1.8.4
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'plant',
'journal',
'userimg',
'django.contrib.sites',
'allauth',
'allauth.account')
Installed Middleware:
('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')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/core/handlers/base.py" in get_response
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/django/django_project/plant/views.py" in plant_main
24. return render(request, 'plant/plant_main.html', context)
File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/shortcuts.py" in render
67. template_name, context, request=request, using=using)
File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/template/loader.py" in render_to_string
99. return template.render(context, request)
File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/template/backends/django.py" in render
74. return self.template.render(context)
File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/template/base.py" in render
208. with context.bind_template(self):
File "/usr/lib/python2.7/contextlib.py" in __enter__
17. return self.gen.next()
File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/template/context.py" in bind_template
237. processors = (template.engine.template_context_processors +
File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/utils/functional.py" in __get__
60. res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/template/engine.py" in template_context_processors
90. return tuple(import_string(path) for path in context_processors)
File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/template/engine.py" in <genexpr>
90. return tuple(import_string(path) for path in context_processors)
File "/usr/local/lib/python2.7/dist-packages/Django-1.8.4-py2.7.egg/django/utils/module_loading.py" in import_string
26. module = import_module(module_path)
File "/usr/lib/python2.7/importlib/__init__.py" in import_module
37. __import__(name)
Exception Type: ImportError at /plant/
Exception Value: No module named context_processors
我遇到了同样的问题,但我正在从1.9.1升级到1.10。我发现设置有点不同。
这是1.9.1中的代码
这是1.10的代码
行
django.core.context_processors.request
在1.10中无效。删除它,代码就可以正常工作了。只是一个提示:当回溯没有提供识别代码行所需的信息时;启用
DEBUG
模式并在浏览器中打开页面会很有帮助。这里有一个很棒的小local_vars
元素,在这里您可以看到发生回溯时的局部变量状态。它可以非常方便!(在我的案例中,它与allauth内部的更改有关)
问题是,在升级到Django 1.8之后,在settings.py中没有根据需要设置模板。我不清楚为什么它在我的电脑上使用Django服务器。
从allauth文档中,我将其粘贴到我的设置文件中:
并将我以前的
TEMPLATE_DIRS
设置的内容复制到模板的DIRS定义中。最终结果如下:根据最近allauth更新的文档,现在需要在模板设置中指定
context_processors
,而不是TEMPLATE_CONTEXT_PROCESSORS
设置。感谢Joey Wilhelm在这个问题上指引我正确的方向。
相关问题 更多 >
编程相关推荐