How to import django.middleware classes into a Google App Engine project?

I am trying to deploy a django project for GAE. After deploying with appcfg.py, I get this error inside GAE. Does anyone 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 following code shows how middleware classes are imported into 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 at this.

+7
source share
3 answers

Install memcache with

 pip install python-memcached 
+5
source

Your caching server might be configured to use memcache. Memcache is now available on google-appengine. You need to use memcache shell from appengine api google.appengine.api.memcache .

You will need to use a custom cache server using django. You may need to implement your own django cache backend, which uses the appengine memcache api. The implementation of the django backend should be trivial, since the functions of the appengine api are easily mapped to the django cache backend. When writing a backend as a reference, you can use django.core.cache.backends.MemcachedCache

+1
source

You have a strange configuration, I suspect that you will encounter many problems.

You are using the GAE library for django 1.4 However, you also imported djangoappengine, which is intended for django-nonrel.

I don't think GAE provided a library and django-unreal work together. I suspect that you are likely to get many strange errors.

If you used pure django-unreal, I think your middleware is configured normally.

Does it work locally and only breaks down when deployed? In this case, you are most likely using django-nonrel locally, but you are not deploying it, so when deploying it uses the version provided by GAE.

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

0
source

All Articles