Persistent Session in CGI

Damjan gdamjan at gmail.com
Wed Aug 30 21:34:56 EDT 2006


> But.. WSGI is the new CGI

Let me give you a minimal example using RhubarbTart (it depends on Paste)

from rhubarbtart import request, response, expose
from rhubarbtart import TartRootController

class Root(TartRootController):
    @expose
    def index(self, msg="Hello world!"):
        response.headers['Content-type'] = 'text/plain'
        return msg

app = Root()

#
# Now to serve it as a CGI script, just:
#
from wsgiref.handlers import CGIHandler
CGIHandler().run(app)

#
# or to server it in a long running python-based HTTP server
#
from paste import httpserver
httpserver.serve(app)

# END of example

Now this is just the begining to show you that it's not hard.
But when you see what EvalException can do for you, you'll beg for more :)

Hint:
from paste.evalexception.middleware import EvalException
app = EvalException(app)
# then serve the app in the paste httpserver ... 
# but make some error in your python code to see it's results


-- 
damjan



More information about the Python-list mailing list