RE: how to write python server page by using mod_python?

Discussion in 'Python' started by Robert Brewer, Mar 5, 2004.

  1. 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
     
    Robert Brewer, Mar 5, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bowen Chiu
    Replies:
    1
    Views:
    548
    Skip Montanaro
    Aug 9, 2003
  2. wenming_hu
    Replies:
    0
    Views:
    289
    wenming_hu
    Mar 5, 2004
  3. Robert Brewer
    Replies:
    1
    Views:
    433
    wenming_hu
    Mar 5, 2004
  4. neha
    Replies:
    1
    Views:
    518
    Brad Teale
    Oct 19, 2005
  5. blbmdsmith
    Replies:
    1
    Views:
    649
    Graham Dumpleton
    Dec 14, 2006
Loading...

Share This Page