[mod_python] Session Management for the beginner

Jim Steil jim at qlf.com
Wed Jan 4 09:45:18 EST 2006


Hi, I'm new to mod_python and apache in general, and am confused about 
how to implement session management.  I'm using the Publisher handler 
and PSP templates.

Here is the relevant portion of my http.conf file:

<Directory "c:/program files/apache group/apache2/htdocs/motion">
      AddHandler mod_python .py
      PythonHandler mod_python.publisher
      PythonAuthenHandler myAuthScript
      PythonDebug On
      AuthType Basic
      AuthName "Restricted Area"
      require valid-user
</Directory>

...and here is my python module:

from mod_python import psp

import time
import mx.ODBC
import mx.ODBC.Windows

def secUserList(req, page='', sortSeq=''):
    if page:
        startPage = int(page)
    else:
        startPage = 1
   
    pageLength = 20
   
    sql = 'call secUser_list(\'' + sortSeq + '\', ' + repr(startPage) + 
', ' + repr(pageLength) + ')'
    db = mx.ODBC.Windows.DriverConnect('DSN=motion;UID=userid;PWD=password')
    c = db.cursor()
    c.execute(sql)
   
    htmlText = ''
    for secUserId, firstName, lastName, logonName, email in c.fetchall():
        htmlText = htmlText + '<tr 
onmouseover="style.backgroundColor=\'#FFF0AF\'; style.cursor=\'hand\';" 
onclick="location.href=\'secUserProfile?secUserId=' + "%i" % secUserId + 
'\'" onmouseout="style.backgroundColor=\'#ffffff\';"><td>' + firstName + 
'</td><td>' + lastName + '</td><td>' + logonName + '</td><td>' + email + 
'</td></tr>\n'
       
    previousPage = 1
    if startPage > 1:
        previousPage = startPage - 1
   
    nextPage = startPage + 1
    c.close()
    db.close()
   
    parmDict = {'title':'User List', 'rowHtml':htmlText, 
'previousPage':previousPage, 'nextPage':nextPage, 'startPage':startPage}
   
    template = psp.PSP(req, filename='secUserList.html')
    template.run(vars = parmDict)


My question is;  How do I implement the session?  Where do I put the 
code?  I want to be able to store my database login credentials in the 
session object.  I'm guessing I'm missing something really obvious, but 
can't seem to get my head around it.  Any help or pointers to good 
examples would really be appreciated.

    -Jim

-- 
Jim Steil
IT Manager
Quality Liquid Feeds
(608) 935-2345
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20060104/49c3679e/attachment-0001.html


More information about the Mod_python mailing list