[Django]-Python Django : No module named security

46👍

I met the same problem. Finnaly, I found I’m using django 1.7.1 to run a 1.8dev generated project. When I switch back to 1.7.1, and remove ‘django.middleware.security.SecurityMiddleware’ in setting.py, it seems ok.

12👍

So, I found a solution :

'django.middleware.security.SecurityMiddleware'

This line is in MIDDLEWARE_CLASSES, from settings.py.
When I delete this line I have no more problems with the security module but I guess this is not a good way to solve the problem … I guess this line is in relation with the crsf token and things like that.

Any other idea to fix the problem ?

👤Zat42

8👍

I ran into this same problem. It turned out that I was inadvertently using my machine’s version of django-admin.py to start my Django project, rather than the one installed within the virtualenv. I ended up having to source bin/activate again after installing django within the virtualenv, before running any of the django-admin commands.

👤iross

1👍

I had the same problem when switching my project from another pc. As i didn’t like very much the option given to remove the

‘django.middleware.security.SecurityMiddleware’

I just created a new project and a new app, change the settings by hand and copy the rest of the files, and it worked 🙂

I’m guessing it has something to do with the secretkey of the project.

1👍

If you previously used a virtualenv for this project make sure that you activate it for the next time that you will use this project source bin/activate or check to see that you use the proper version of django.

If you want to remove some middlewares then you need to make sure of what you are doing.

0👍

use this it worked for me

MIDDLEWARE_CLASSES = [
'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

0👍

I guess this happen in django version 1.7.x when you are trying to open project created using django version higher than 1.7.x

removing 'django.middleware.security.SecurityMiddleware' helps but it create another problem 'session error' or something

to fix this:

pip uninstall django==1.7.x //your current version of django installed
pip install django==1.9.x //or version that is compatible with the project

-2👍

(myvenv) pip uninstall django==(version)
(myenv) pip install django==(version)

Just it.

Leave a comment