ImportError:没有名为 context_processors 的模块

ImportError:没有名为 context_processors 的模块

我使用 pip 安装了 django-paypal 库,但是此后我原来的 django 版本升级了,因此我的运行代码出现了错误。

所以我卸载了 django-paypal。但我仍然收到相同的错误。错误是

Import Error: No module named context_processors

我的django老版本是1.8.7
现在升级到1.10

错误消息:

Unhandled exception in thread started by <function wrapper at 0x7f7cb8032410>
Traceback (most recent call last):
  File "/home/v08/.local/lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/home/v08/.local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 121, in inner_run
    self.check(display_num_errors=True)
  File "/home/v08/.local/lib/python2.7/site-packages/django/core/management/base.py", line 385, in check
    include_deployment_checks=include_deployment_checks,
  File "/home/v08/.local/lib/python2.7/site-packages/django/core/management/base.py", line 372, in _run_checks
    return checks.run_checks(**kwargs)
  File "/home/v08/.local/lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/home/v08/.local/lib/python2.7/site-packages/django/core/checks/urls.py", line 14, in check_url_config
    return check_resolver(resolver)
  File "/home/v08/.local/lib/python2.7/site-packages/django/core/checks/urls.py", line 24, in check_resolver
    for pattern in resolver.url_patterns:
  File "/home/v08/.local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/v08/.local/lib/python2.7/site-packages/django/urls/resolvers.py", line 310, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/v08/.local/lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/home/v08/.local/lib/python2.7/site-packages/django/urls/resolvers.py", line 303, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/v08/django/FirstProject/FirstProject/urls.py", line 25, in <module>
    url(r'^', include('Car.urls')),
  File "/home/v08/.local/lib/python2.7/site-packages/django/conf/urls/__init__.py", line 50, in include
    urlconf_module = import_module(urlconf_module)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/v08/django/FirstProject/Car/urls.py", line 2, in <module>
    from . import views
  File "/home/v08/django/FirstProject/Car/views.py", line 7, in <module>
    from django.core.context_processors import csrf
ImportError: No module named context_processors

答案1

django1.8 的 Setting.py:- 在TEMPLATES

            'django.template.context_processors.debug',
            'django.template.context_processors.request',
            'django.contrib.auth.context_processors.auth',
            'django.contrib.messages.context_processors.messages',
            'django.core.context_processors.i18n',
            'django.core.context_processors.media',
            'django.core.context_processors.static',
            'django.core.context_processors.tz',

setting .py我遇到了以下问题,应该在文件中进行更改

django1.10 的 Setting.py:- 在TEMPLATES

            'django.contrib.auth.context_processors.auth',
            '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',

并改变views.py:-

版本 1.8 代码:-

from django.core.context_processors import csrf
from django.core.context_processors import csrf

版本 1.10 代码:-

from django.views.decorators import csrf
from django.views.decorators.csrf import csrf_protect

相关内容