user1826178
user1826178

Reputation: 103

How should I import django.middleware classes in Google App Engine project?

I am trying to deploy my django project to GAE. After deploying using appcfg.py I get this error inside GAE. Does anybody know how to solve this problem?

Traceback (most recent call last):
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime 
  /wsgi.py", line 223, in Handle
  result = handler(dict(self._environ), self._StartResponse)
  File "/base/python27_runtime/python27_lib/versions/third_party/django-1.4/django
  /core/handlers/wsgi.py", line 219, in __call__
  self.load_middleware()
  File "/base/python27_runtime/python27_lib/versions/third_party/django-1.4/django
  /core/handlers/base.py", line 47, in load_middleware
  raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % 
  (mw_module, e))

  ImproperlyConfigured: Error importing middleware django.middleware.cache: "No module 
  named memcache"

The next code shows how the middleware classes are imported in my project.settings:

from djangoappengine.settings_base import *

....

MIDDLEWARE_CLASSES = (
'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.cache.FetchFromCacheMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)

Thanks for looking into this.

Upvotes: 7

Views: 4240

Answers (3)

dragonx
dragonx

Reputation: 15143

You have a strange configuration, I suspect you'll run into a LOT of problems.

You're using the GAE provided library for django 1.4 However, you've also got djangoappengine imported, which is designed for django-nonrel.

I don't think the GAE provided library and django-nonrel work well together. I suspect you'll likely get a lot of weird errors.

If you were using pure django-nonrel, I think your middleware is set up ok.

Does this work locally, and only break when you deploy? In that case you're most likely using django-nonrel locally, but you're not deploying it - so when deployed, it's using the GAE provided version.

Make sure django-nonrel is in your project folder. And don't enable django 1.4 in your app.yaml.

Upvotes: 0

Ski
Ski

Reputation: 14497

Your caching backend is probably configured to use memcache. Memcache is now available on google-appengine. You need to use memcache wrapper from appengine api google.appengine.api.memcache.

You will need to use a custom cache backend with django. You might need to implement your own django cache backend which uses appengine's memcache api. Implementing a django backend should be trivial because functions from appengine api maps easily to django cache backend. When writing a backend as a reference you can use django.core.cache.backends.MemcachedCache

Upvotes: 1

Neel
Neel

Reputation: 21297

Install memcache with

pip install python-memcached

Upvotes: 5

Related Questions