web-dev-qa-db-ja.com

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
4
Rohit Gavfale

Django1.8のSetting.py:- in 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:- in 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
4
Rohit Gavfale