WSGI - How Does It Affect Me?
ianb at colorstudy.com
Mon Oct 9 17:30:56 CEST 2006
Gregory Piñero wrote:
> What I'm most confused about is how it affects me. I've been writing
> small CGI programs in Python for a while now whenever I have a need
> for a web program. Is CGI now considered "Bad"? I've just always
> found it easier to write something quickly with the CGI library than
> to learn a framework and fool with installing it and making sure my
> web host supports it.
There's two aspects to CGI. As a method of deploying a web
application, it is fine (though slow). You can still deploy your
applications as CGI if you write them with WSGI. (This is covered some
in PEP 333)
There are some bad parts of CGI too, which won't work with WSGI. An
example is using "print" for output. WSGI is neutral about how your
application will run -- maybe it'll be a CGI script, maybe it'll be a
threaded server with long-running processes, maybe a forking server.
Also, you can't have statements at the module level, like you would
with a CGI script. All your code needs to be in functions. I think
these are all good ideas anyway.
One advantage of WSGI is that in addition to CGI you can easily set up
an HTTP server (there's one in wsgiref, for example). Then you can
develop and test your application locally.
More information about the Python-list