/home/hide/website/www/python/pages/handler.py
from mod_python import Session,apache def handler(req): session = Session.Session(req) try: session['counter'] += 1 except: session['counter'] = 1 session.save() req.write("<html>\n"); req.write("<body>\n"); req.write("<h1>\n"); req.write("Hello.%d\n" % session['counter']); req.write("</h1>\n"); req.write("</body>\n"); req.write("</html>\n"); return apache.OK
/home/hide/website/www/dev/.htaccess
Order allow,deny
allow from all
SetHandler mod_python
PythonPath sys.path+[‘/home/hide/website/www/python’]
PythonHandler pages.handler
test.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName py.hdknr.local:80
DocumentRoot /home/hide/website/www
<Directory /home/hide/website/www >
Options All
AllowOverride All
Order allow,deny
allow from all
</Directory>
LogLevel warn
ErrorLog /var/log/apache2/py.hdknr.local.error.log
CustomLog /var/log/apache2/py.hdknr.local.access.log combined
ServerSignature On
DirectoryIndex index.php index.html index.htm
</VirtualHost>
deb1:/home/hide# /etc/init.d/apache2 restart
handler.pyにデバックコードを入れる。
req.write(session._dbmfile+"<br>\n")
deb1:~# od -c /tmp/mp_sess.dbm
0000000 001 a 025 006
0000020 \b 020 \b
0000040 002
0000060 250 302 \b 001 003 223 C 307 200
0000100 224 \v 001 001
0000120 321 215 h ^
0000140 001 001
0000160
*
0020000 001 002
0020020 002 U 017 002 337 017 U 017
0020040 002
0020060 250 302 \b 001 003 223 C 307 200
0020100 224 \v 001 001
0020120 321 215 h ^
0020140 001 001
0020160
*
0027520 001 001 ( d p 1 \n S ' _ t i
0027540 m e o u t ' \n p 2 \n I 1 8 0 0 \n
0027560 s S ' _ c r e a t e d ' \n p 3 \n
0027600 F 1 2 1 4 2 3 4 8 1 8 . 6 7 7 8
0027620 6 9 1 \n s S ' _ d a t a ' \n p 4
0027640 \n ( d p 5 \n S ' c o u n t e r '
0027660 \n p 6 \n I 3 1 \n s s S ' _ a c c
0027700 e s s e d ' \n p 7 \n F 1 2 1 4 2
0027720 3 6 2 6 9 . 5 7 7 4 6 7 \n s . 001
0027740 b 5 d 2 c e b 2 7 3 1 d b 9 f 5
0027760 5 b 7 e 0 8 d 3 2 1 d d e 8 d e