views:

247

answers:

2

To help further my understanding of WSGI I'm looking for a diagram which explains the flow of an application, from webserver (eg. apache) through a number of middlewares to "code" (as in, the print "hello world" bit).

I've read various articles regarding WSGI from wsgi.org, but it's still not "clicking" for me and as for diagrams Google isn't bringing anything useful back except this for django which, while interesting, is expecting the user to understand how middleware links-up and such.

Since "a picture is worth a thousand words", are there any diagrams out there which get a bit lower/more simplistic than this?

+3  A: 

I don't know if I can provide the answer you are looking for but the diagram you linked to shows more than just wsgi. The wsgi layer ends at the second line on the diagram. After that it's application specific.

WSGI is more an interface definition or contract that boils down to somehow you provide a function which takes a dictionary (environ) which represents the contents of the current request. and a function to call when you are ready to start the response(start_response).

The start_response method that you call needs a HTTP status code('200 OK') and a list of HTTP headers([('content-type', 'text/html')]).

def say_hello(envron={},start_response):
    start_response('200 OK', [('content-type', 'text/html')])
    return ["Hello from WSGI"]

Linking up your web server to your wsgi app is specific to your webserver I think and information on how the webserver arrives at the environ dictionary and a callback for your code to call is the webserver magic that you probably don't need to be concerned about. And as long as you obey the protocol, the webserver doesn't need to care how you arrived at your list of output that constitutes your response from your application.

The Paste documentation helped me a LOT. You may find it useful. BTW, Paste is a bunch of useful things that help you utilize WSGI.And the docs are very good for understanding how to use WSGI and by extension Paste.

I know you asked for a diagram sorry. :(

Tom Willis
The link to paste(WSGI) documentation was very helpful. Helped me understand WSGI. +1
Ingenutrix
+6  A: 

I like the diagram from Ian Bicking's WSGI - A Series of Tubes.

Perfect! All it takes is some pointy arrows, some colored boxes, and "understanding" slots into place. Thanks!
digitala
And the crayon style is refreshing :)
HAH, that presentation is pretty good. I had no idea it existed. FWIW, the author of the presentation created Paste which I consider to one of the best resources for learning WSGI.
Tom Willis
That's great lutz!
thethinman