[Django]-How to adding middleware to Appengine's webapp framework?

6đź‘Ť

âś…

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

0đź‘Ť

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

0đź‘Ť

“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

Leave a comment