'CsrfViewMiddleware'对象不可迭代

时间:2016-08-29 10:18:59

标签: python django django-templates django-views django-csrf

我是Django的新手,我刚从另一位开发人员手中接过了这个项目。到目前为止我所做的就是从git克隆代码并安装依赖项。

设置项目后立即运行python manager.py runserver并转到localhost:8000/admin我收到错误消息,指出TypeError at /admin/login/'CsrfViewMiddleware' object is not iterable

  

回溯:

     

文件   “/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/core/handlers/exception.py”   在内心     39. response = get_response(request)

     

文件   “/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/core/handlers/base.py”   在_legacy_get_response中     249. response = self._get_response(request)

     

文件   “/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/core/handlers/base.py”   在_get_response中     217. response = self.process_exception_by_middleware(e, request)

     

文件   “/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/core/handlers/base.py”   在_get_response中     215. response = response.render()

     

文件   “/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/template/response.py”   在渲染中     109. self.content = self.rendered_content

     

文件   “/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/template/response.py”   在rendered_content中     86. content = template.render(context, self._request)

     

文件   “/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/template/backends/django.py”   在渲染中     66. return self.template.render(context)

     

文件   “/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/template/base.py”   在渲染中     206. with context.bind_template(self):

     

__enter__中的文件“/usr/lib/python3.5/contextlib.py”     59. return next(self.gen)

     

文件   “/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/template/context.py”   在bind_template中     236. updates.update(processor(self.request))

     

异常类型:/ admin / login /

中的TypeError      

异常值:'CsrfViewMiddleware'对象不可迭代

enter image description here

我会从源代码发布代码,但我无法确定源代码中可能出现的原因。

我的settings.py:

import os
from datetime import datetime
from django.conf.global_settings import EMAIL_USE_SSL
INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'ourapp',
    'social.apps.django_app.default',
    'sendgrid',
    'corsheaders',
)

MIDDLEWARE_CLASSES = (
    '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',
    'ourapp.middleWare.authenticationMiddleware.AuthenticationMiddleware'
)

ROOT_URLCONF = ''

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
        'django.middleware.csrf.CsrfViewMiddleware',
        'corsheaders.middleware.CorsMiddleware',
                'social.apps.django_app.context_processors.backends',
                'social.apps.django_app.context_processors.login_redirect',
            ],
        },
    },
]

(抱歉缺少缩进。) 关于如何从这里开始的任何想法将不胜感激!

1 个答案:

答案 0 :(得分:4)

尝试从'django.middleware.csrf.CsrfViewMiddleware',删除TEMPLATES。也可能是'corsheaders.middleware.CorsMiddleware',