Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 400
user1826178 Avatar asked Nov 20 '12 09:11

user1826178


2 Answers

Install memcache with

pip install python-memcached
like image 173
Nilesh Avatar answered Oct 27 '22 23:10

Nilesh


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

like image 31
Ski Avatar answered Oct 27 '22 23:10

Ski