mod_python on Win32 [new problem]

David LeBlanc whisper at oz.nospamnet
Fri May 4 14:15:00 EDT 2001


[This followup was posted to comp.lang.python and a copy was sent to the 
cited author.]

In article <tBrI6.8767$R2.6843403 at newsrump.sjc.telocity.net>, dsavitsk at e-
coli.net says...
> [off topic question]
> 
>  * * *
> 
> > No, dunno. I'd post the question on the modpython mailing list.
> >
> > Gerhard
> 
> that's probably the right answer, thanks
> 
> 
> 
Actually, it's fairly simple - check out the examples in the mod-python 
doc about handlers (although, not very informative). I had this problem 
too and it was the lack of creating a handler def... here is the trivial 
example that I got to work for me (mind the word wraps that screwed up 
indenting):

from mod_python import apache
import os

import HTMLutil

def environmentPrint(req):
    req.write("<h1>Hello World!</h1>\n")
    req.write("<h2><font color=\"red\">Environment 
Variables</font></h2>")
    req.write("<p>")
    req.write("<table width=50% border=1>")
    keys = os.environ.keys()
    keys.sort()
    for key in keys:
      req.write("<tr>")
      req.write("<td><p>" + key + "</p></td>")
      req.write("<td><p>" + os.environ[key] + "</p></td>")
      req.write("</tr>")
    req.write("</table>")
    req.write("</p>")

def printPYSrc (req):
  tmp = HTMLutil.markup("k:/python/lib/site-packages/HTMLgen.py")
  req.write(tmp.__str__())

def handler(req):
  req.content_type = "text/html"
  req.send_http_header()
  req.write("<html>")
  req.write("<title>Test</title>")
  #req.write("<link rel=\"stylesheet\" type=\"text/css\" 
href=\"k:/apache/htdocs/davesweb.css\">")
  req.write("<body>")
  environmentPrint(req)
  #printPYSrc(req)   
  req.write("</body>")
  req.write("</html>")
  return apache.OK

>From my httpd.conf:
  <Directory "k:/apache/htdocs/test"> 
    AddHandler python-program .py
    PythonHandler mptest 
    PythonDebug On 
  </Directory>

Good luck,

Dave LeBlanc



More information about the Python-list mailing list