I get this message in Django after running runserver:
ImportError at /admin/login/ cannot import name 'Session' Request
Method: POST Request
URL: http://127.0.0.1:8000/admin/login/?next=/admin/ Django
Version: 2.0.5 Exception Type: ImportError Exception Value: cannot
import name 'Session' Exception
Location: C:\HOMEWARE\Anaconda3-Windows-x86_64\lib\site-packages\django\contrib\sessions\backends\db.py
in get_model_class, line 23 Python
Executable: C:\HOMEWARE\Anaconda3-Windows-x86_64\python.exe Python
Version: 3.6.4
This is part of my code in settings.py:
# Application definition
INSTALLED_APPS = [
'AppFinal.apps.AppfinalConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
#'AppFinal'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'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',
]
ROOT_URLCONF = 'ProjetFinal.urls'
I've checked everything, but it seems alright, does anyone knows how to handle this kind of error?
thanks
Related
I have gone through literally all SO links, reinstalled django and django-cors-headers and followed this to the T and yet we get
pre flight error cross origin not allowed
Django version 2.1.7
relevant sections of settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'corsheaders',
'uploads.core',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'corsheaders.middleware.CorsPostCsrfMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
CORS_ORIGIN_ALLOW_ALL = True
CorsMiddleware should be placed as high as possible, especially before any middleware that can generate responses such as Django’s CommonMiddleware or Whitenoise’s WhiteNoiseMiddleware. If it is not before, it will not be able to add the CORS headers to these responses.
MIDDLEWARE = [
'corsheaders.middleware.CorsMiddleware', # <-- should be at the top
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'corsheaders.middleware.CorsPostCsrfMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
This is an issue is because the given Django package is for Djangov2.2>
Here you are using 2.1 so it doesn't support it.
You need to manually pass headers from HttpResponse
I've did all the steps which are described in the docs and got the toolbar in admin site. However, I can't get it work in the project frontend side.
Here is my settings:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'debug_toolbar',
...
]
MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
]
INTERNAL_IPS = ('127.0.0.1', 'localhost',)
I've googled a lot already and non of the proposed solution are not working for me: workaround that shows toolbar even if debug=False, playing with different parameters like INTERCEPT_REDIRECTS=False/True, specifying JQUERY_URL since there is a local jquery which is used by frontend.
I've asked for help from frontend dev, but he can't understand why there is no any configs for client side.
Frontend is using nodes.js and listens on 3000 port than forwards to localhost:8081.
Django version 1.10, django-debug-toolbar 1.9.1.
The site is working fine but when I switch to http://127.0.0.1:8000/admin/ it shows AttributeError at /admin/ .I tried to include MIDDLEWARE_CLASSES in the mysite/settings.py but to no avail . Here are some details :
Django mysite.settings
INSTALLED_APPS = [
'personal',
'blog',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE_CLASSES = [
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
http://127.0.0.1:8000/admin/ page ::
Django mysite.urls ::
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^', include('personal.urls')),
url(r'^blog/', include('blog.urls')),
]
Am I missing something? Ask for more info if required .
Thanks!
You should know that altering the order of the middlewares can cause serious problems, which it did in your case.
So my advice to you is to add your apps at the end of the INSTALLED_APPS and create a new django project and replace your middlewares list with the middlewares list of the newly created project or try with these
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'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',
'django.middleware.locale.LocaleMiddleware',
]
I get the following error after the first steps of django-allauth installation.
ImproperlyConfigured at /admin/
Error importing module django.contrib.messages.context_processors.messagesallauth.account.context_processors: "No module named messagesallauth.account.context_processors"
Request Method: GET
Request URL: http://localhost:8000/admin/
Django Version: 1.6.6
Exception Type: ImproperlyConfigured
Exception Value:
Error importing module django.contrib.messages.context_processors.messagesallauth.account.context_processors: "No module named messagesallauth.account.context_processors"
Exception Location: /home/miguelfg/workspace/python_environments/tdcp_observatorio/local/lib/python2.7/site-packages/django/utils/importlib.py in import_module, line 40
Python Executable: /home/miguelfg/workspace/python_environments/tdcp_observatorio/bin/python2.7
Python Version: 2.7.3
Python Path:
['/home/miguelfg/workspace/projects/python/tdcp_observatorio',
'/home/miguelfg/workspace/projects/python/tdcp_observatorio',
'/home/miguelfg/workspace/python_environments/tdcp_observatorio/lib/python2.7',
'/home/miguelfg/workspace/python_environments/tdcp_observatorio/lib/python2.7/plat-linux2',
'/home/miguelfg/workspace/python_environments/tdcp_observatorio/lib/python2.7/lib-tk',
'/home/miguelfg/workspace/python_environments/tdcp_observatorio/lib/python2.7/lib-old',
'/home/miguelfg/workspace/python_environments/tdcp_observatorio/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/home/miguelfg/workspace/python_environments/tdcp_observatorio/local/lib/python2.7/site-packages',
'/home/miguelfg/workspace/python_environments/tdcp_observatorio/local/lib/python2.7/site-packages/PIL']
Server time: Wed, 3 Sep 2014 12:29:34 +0200
I have gone through all installation steps, including syncdb or migrate commands, until login the django admin interface and add a Site and Social Apps.
Here parts of my settings file:
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.debug',
'django.core.context_processors.i18n',
'django.core.context_processors.media',
'django.core.context_processors.static',
'django.core.context_processors.request',
'django.contrib.messages.context_processors.messages'
# allauth specific context processors
"allauth.account.context_processors.account",
"allauth.socialaccount.context_processors.socialaccount",
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'custom_middleware.memory.MemoryUsageMiddleware',
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
...
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',
'allauth.socialaccount.providers.twitter',
'allauth.socialaccount.providers.google',
)
SITE_ID = 1
...
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
I'm using allauth in another project and I've never got this. Any help is very welcome :-)
I am a newbie to django and after going through some django tutorial i have started using django-cms(I had a requirement to develop a cms site with django-cms).
I have edited the settings file and added all the middlewares,apps that are necessary for cms, so everything is going fine and started developing html templates, but sometimes after i restarting the server and getting the below weird errors
Error_1
Django Version: 1.4.3
Exception Type: ImportError
Exception Value:
cannot import name plugin_pool
Exception Location: /usr/lib/python2.7/site-packages/cms/admin/__init__.py in <module>, line 7
Python Executable: /usr/bin/python
Error_2
Django Version: 1.4.3
Exception Value: Reverse for 'pages-root' with arguments '()' and keyword arguments '{}' not found
Exception Location: /usr/lib/python2.7/site-packages/cms/models/__init__.py in new_reverse, line 67
Python Executable: /usr/bin/python
................
These are the two errors i am facing sometimes and don't know why they are encountered because they are appearing suddenly, can i know how to avoid these errors
some of the settings are below
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'cms.middleware.multilingual.MultilingualURLMiddleware', #CMS
'cms.middleware.page.CurrentPageMiddleware', #CMS
'cms.middleware.user.CurrentUserMiddleware', #CMS
'cms.middleware.toolbar.ToolbarMiddleware', #CMS
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'cms',
'mptt',
'menus',
'south',
'sekizai',
'reversion',
'cms.plugins.text',
'filer',
'easy_thumbnails',
'cmsplugin_filer_file',
'cmsplugin_filer_image',
'cmsplugin_filer_teaser',
'cms.plugins.link',
'cms_themes',
)
Using Django 1.4.3 I have had the same problem with this error:
ImportError at / - cannot import name plugin_pool
after research i have found that simply by updating my django to version 1.4.5
my plugin_pool import error has gone away.