views:

1038

answers:

4

Im using the appengine webapp framework (link). Is it possible to add Django middleware? I cant find any examples. Im currently trying to get the firepython middleware to work (link).

+1  A: 

Could you provide any details on your failure?

AFAIK Google App Engine lets you use django middleware as long as it does not use django models/ORM.

BTW. Thanks for pointing out Firepython, looks sweet :)

ohnoes
Im wanting to use middleware with the webapp framework (see link about), there is no settings.py and i cant find any examples of how to configure middleware.
Sam
+4  A: 

It's easy: You create the WSGI application as per normal, then wrap that application in your WSGI middleware before executing it.

See this code from Bloog to see how firepython is added as middleware.

Nick Johnson
Thats a good start but im looking for a more generic way to add any django middleware. Ill have a look at how the FirePythonWSGI works
Sam
That _is_ a generic way to add WSGI middleware. As far as Django's idea of 'middleware' goes, you'd need to consult the Django manual for that.
Nick Johnson
A: 

The GAE webapp framework does not map one to one to the Django framework. It would be hard to do what you want without implementing some kind of adapter yourself, I do not know of any third party handler adapters to do this.

That said, I generally use the app-engine-patch so I can use the latest 1.0.2 Django release with AppEngine, and then you can just include the Django middleware the normal way with the setup.py file. If you needed to, you could probably look through the app-engine-patch's adapter to see how they do it, and start with that as a framework.

dar
A: 

"Middleware" as understood by Django is a kind of request/response processor, quite different from what WSGI calls "middleware". Think: django-like middleware will add session attribute to request object basing on what Beaker (WSGI middleware) has put in environ['beaker.session']. While adding WSGI middleware to the stack should be straightforward (you already work on WSGI level in your main.py), adding request/response processor depends on how request and response are abstracted from WSGI.

How this can be done using Werkzeug (which is basic WSGI toolset) is described in Werkzeug's wiki and in one of its contrib modules.

zgoda