I’m new to django and Google App Engine, and I’m having trouble with using the datastore. Every time I make a query, such as
db.GqlQuery("SELECT * FROM Listing ORDER BY date DESC LIMIT 10")
I receive the error:
'WSGIRequest' object has no attribute 'user'
This error seems to be generated in context_processors.py within the django core. Now, the advice I’ve found on the Internet said to comment out user-related INSTALLED_APPS and MIDDLEWARE_CLASSES, but this does not seem to help. My code looks like this:
MIDDLEWARE_CLASSES = (
# 'django.middleware.common.CommonMiddleware',
# 'django.contrib.sessions.middleware.SessionMiddleware',
# 'django.contrib.auth.middleware.AuthenticationMiddleware',
# 'django.middleware.doc.XViewMiddleware',
)
INSTALLED_APPS = (
# 'django.contrib.auth',
'django.contrib.contenttypes',
# 'django.contrib.sessions',
'django.contrib.sites',
)
My Listing object is defined as the following (it had a author property earlier, but this is now commented out and the object was redefined with a new name):
class Listing(db.Model):
#author = db.UserProperty()
address = db.StringProperty()
date = db.DateTimeProperty(auto_now_add=True)
coords = db.GeoPtProperty()
Does anyone know what is causing this error, and how to fix it? Is it perhaps a case of having to reset the settings somehow?
UPDATE
The solution suggested by sdolan seems to be to add the following to the settings.py of the app:
TEMPLATE_CONTEXT_PROCESSORS = (
“django.core.context_processors.debug”,
“django.core.context_processors.i18n”)
This effectively removes the third default processor, django.core.context_processors.auth (which shouldn’t be there because for AppEngine we don’t want Django’s auth component).
Thank you, sdolan, for the solution! hopefully someone else can use it, too. 🙂
@Nick, I think it’s worth putting this golden piece about CONTEXT_PROCESSORS in the tutorial (http://code.google.com/appengine/articles/django.html)
(Original followup to the question)
Have the same problem, looking for solution…. All works fine when settings.py contains
DEBUG = True
but this error pops up (and kills my motivation to proceed with learning) when I switch to
DEBUG = False
@Nick Johnson, here’s the stack trace: