By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,526 Members | 2,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,526 IT Pros & Developers. It's quick & easy.

Persistent Session in CGI

P: n/a
Hi,

I have started a new small web project, and was wondering if there are
any good guides on how to do Persistent Sessions and Authentication
using python and CGI. I don't really want too use Zope, because It's
probably overkill for my tiny project.

Aug 27 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
ke***********@gmail.com writes:
I have started a new small web project, and was wondering if there are
any good guides on how to do Persistent Sessions and Authentication
using python and CGI. I don't really want too use Zope, because It's
probably overkill for my tiny project.
The simplest thing to do is put all the session info into a browser
cookie. That limits the amount of session info but maybe you can live
with that. You should encrypt and authenticate the cookie to prevent
the user from tampering with it.
Aug 27 '06 #2

P: n/a

ke***********@gmail.com wrote:
Hi,

I have started a new small web project, and was wondering if there are
any good guides on how to do Persistent Sessions and Authentication
using python and CGI. I don't really want too use Zope, because It's
probably overkill for my tiny project.
You could try my 'logintools' CGI module (mini framework really, but
very mini).

It handles authentication for you, and provides a mechanism that you
could use to create persistent sessions.

http://www.voidspace.org.uk/python/logintools.html

(It uses cookies).

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

Aug 27 '06 #3

P: n/a
I have started a new small web project, and was wondering if there are
any good guides on how to do Persistent Sessions and Authentication
using python and CGI. I don't really want too use Zope, because It's
probably overkill for my tiny project.
Since you only mention Zope...
Why not use TurboGears or Pylons or CleverHarold ... or anything WSGI based.
Or if you want to make something minimal you could try Paste with
(optionally) RhubarbTart.

But.. WSGI is the new CGI (the lowest common denominator) in Python web
development. So use it.
The benefits:
You can run your app as CGI, in mod_python, as a standalone http server,
with SCGI/FastCGI.
You'll benefit from authentication and session middleware. Middleware is a
great WSGI concept, there are also caching middlewares etc..

--
damjan
Aug 31 '06 #4

P: n/a
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
Aug 31 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.