Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'WSGIRequest' object has no attribute 'session'

I keep getting this error at random times and whenever I touch the django.wsgi file, it gets fixed only to happen again after a few hours. I'm lost as to what to do. my middleware_classes is as follows:

MIDDLEWARE_CLASSES = (
    'django.middleware.cache.UpdateCacheMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.middleware.csrf.CsrfResponseMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.middleware.facebookConnectMiddleware.FacebookConnectMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.cache.FetchFromCacheMiddleware',
    'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
)

The error always occurs in the facebook middleware when i do an "if request.session" statement. Thanks

like image 439
kingsley Avatar asked Jul 14 '10 14:07

kingsley


Video Answer


1 Answers

Make sure the SessionMiddleware is first in your MIDDLEWARE_CLASSES.

like image 196
Jonatan Littke Avatar answered Oct 11 '22 07:10

Jonatan Littke