wanderingProgrammer wanderingProgrammer - 1 year ago 88
Python Question

'CsrfViewMiddleware' object is not iterable

I am new to Django, and I just took over from another developer on this project. All I have done so far is clone the code from git and install the dependencies.

Immediately after setting up the project, and running

python manager.py runserver
and going to
localhost:8000/admin
I get an error stating the
TypeError at /admin/login/
,
'CsrfViewMiddleware' object is not iterable
:


Traceback:

File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/core/handlers/exception.py"
in inner
39.
response = get_response(request)


File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/core/handlers/base.py"
in _legacy_get_response
249.
response = self._get_response(request)


File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/core/handlers/base.py"
in _get_response
217.
response = self.process_exception_by_middleware(e, request)


File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/core/handlers/base.py"
in _get_response
215.
response = response.render()


File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/template/response.py"
in render
109.
self.content = self.rendered_content


File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/template/response.py"
in rendered_content
86.
content = template.render(context, self._request)


File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/template/backends/django.py"
in render
66.
return self.template.render(context)


File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/template/base.py"
in render
206.
with context.bind_template(self):


File "/usr/lib/python3.5/contextlib.py" in
__enter__

59.
return next(self.gen)


File
"/home/abhay/code/virtualenvironments/leaguesx/lib/python3.5/site-packages/django/template/context.py"
in bind_template
236.
updates.update(processor(self.request))


Exception Type: TypeError at /admin/login/

Exception Value: 'CsrfViewMiddleware' object is not iterable


enter image description here

I would post code from the source code but I can't figure where in the source the cause of this might possibly be.

My 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',
],
},
},
]


(Sorry about the lack of indentation.)
Any ideas on how to proceed from here would be greatly appreciated!

Answer Source

Try removing 'django.middleware.csrf.CsrfViewMiddleware', from TEMPLATES. Probably 'corsheaders.middleware.CorsMiddleware', too

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download