how to write python server page by using mod_python?
Robert Brewer
fumanchu at amor.org
Fri Mar 5 12:14:59 EST 2004
wenming_hu wrote:
> according to your guide, i have succeed in configuring the
> apache...And I have two files , nothing else but
> dispatch.py and welcome.htm, in the
> folder f:\pspsite,
>
> the dispathch.py has the following code:
>
> # dispatch.py
> from mod_python import apache
>
> def handler(req):
> return apache.OK
>
> Then i restart the apache, enter the URL
> "http://localhost/web" in my web
> browser, but get nothing.
You don't _need_ welcome.htm. Try this first: rewrite dispatch.py to:
from mod_python import apache
def handler(req):
req.write(""""<html>
<head><title>welcome to this site!</title></head>
<body>
<center><h1>Hello, world! This is a new site!</h1></center>
</body>
</html>""")
return apache.OK
If you truly want to keep the HTML separate (and I think you should),
begin by rewriting dispatch.py to:
from mod_python import apache
import codecs
import os.path
localDir = os.path.dirname(__file__)
def handler(req):
atoms = aRequest.uri.split("/")
script = atoms.pop()
newFileName = os.path.join(localDir, script)
infile = codecs.open(newFileName, "r", "ISO-8859-1")
req.write(infile.read().replace(u'\r\n', u'\n'))
infile.close()
return apache.OK
Hope that helps!
Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org
More information about the Python-list
mailing list