|
Joshua Ginsberg
listspam at flowtheory.net
Thu Jun 2 18:55:33 EDT 2005
Hi Timothy --
I suppose the documentation doesn't have a step-by-step because there's
really not a step-by-step to it.
When you create a Session object, it looks for a cookie called pysid in
the client's browser. If that cookie does not exist, creating the
Session object sets the cookie in the client's browser.
So for example:
<%
# sessionfu.psp
from mod_python import Session
import pprint
pp = pprint.PrettyPrinter()
sess = Session.Session(req)
newkey = form.getfirst('newkey','')
newvalue = form.getfirst('newvalue','')
%>
<html>
<head>
<title>Session-Fu</title>
</head>
<body>
<%
if sess.is_new():
req.write('''<p>This is a new session.</p>''')
else:
if newkey != '':
# Since Session is an extension of dict, we can assign key/value
pairs to it
sess[newkey] = newvalue
req.write('''<p>This is an existing session.</p>''')
# dump the keys and values in the session already
req.write('''<pre>'''+pp.pformat(sess)+'''</pre>''')
%>
<!-- With this form you can set new keys and values in the session -->
<form action="sessionfu.psp">
<p>Key: <input name="newkey" type="text" /> Value: <input
name="newvalue" type="text" /> <input type="submit" /></p>
</form>
</body>
</html>
I haven't compiled the above, but you get the gist.
-jag
-------------- next part --------------
A non-text attachment was scrubbed...
Name: unknown.jpg
Type: image/jpeg
Size: 1984 bytes
Desc: not available
Url : http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20050602/0ad8ef63/unknown.jpg
-------------- next part --------------
Joshua Ginsberg -- joshg at brainstorminternet.net
Brainstorm Internet Network Operations
970-247-1442 x131
On Jun 2, 2005, at 4:13 PM, Timothy Kendall wrote:
> Sorry for posting such a beginner's question, but...
>
> I've been using Python for some time, but I'm new to mod_python. I
> need to learn how to implement sessions. I've been through section
> 4.8 of the mod_python manual, but what's there doesn't tell me how to
> proceed (not so that my admittedly deficient mind can grasp it,
> anyway). Is there a step-by-step xplanation anyone can point me to?
> Seems like there must be, but I can't seem to find one.
>
> Thank you.
>
> Timothy Kendall
>
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>
|