How to use python or mod_python file to handle HTML form?

Nancy wxling3 at hotmail.com
Tue Jul 27 22:13:31 EDT 2004


Hi, Guys,
   I am new to Python. I am trying to following the example on 
   http://www.modpython.org/live/current/doc-html/tut-pub.html  
   In this example, it gives the following html code,
    <form action="form.py/email" method="POST">
      Name:    <input type="text" name="name"><br>
      Email:   <input type="text" name="email"><br>
      Comment: <textarea name="comment" rows=4 cols=20></textarea><br>
      <input type="submit">
  </form>
===============
  And form.py:
==============
import smtplib
WEBMASTER = "webmaster"   # webmaster e-mail
SMTP_SERVER = "localhost" # your SMTP server
def email(req, name, email, comment):
        if not (name and email and comment):
        return "A required parameter is missing, \
               please go back and correct the error"
     msg = """\
From: %s
Subject: feedback
To: %s
I have the following comment:
%s
Thank You,
%s
""" % (email, WEBMASTER, comment, name)
    conn = smtplib.SMTP(SMTP_SERVER)
    conn.sendmail(email, [WEBMASTER], msg)
    conn.quit()
    # provide feedback to the user
    s = """\
<html>
Dear %s,<br>
Thank You for your kind comments, we
will get back to you shortly.
</html>""" % name
    return s
=====================
  My environment is
  1) Apache 2.0 server runs on WinXP Pro using 8080 port (IIS runs at
same time on 80 port)
  2) I don't have any permission to access any SMTP server.
  3) I don't want to install any SMTP server on my PC.
  Now the question is,
  I cann't run above example code since I don't have SMTP server on my
PC. How can I use my form.py to handle HTML form?
 
   Thanks a lot.

Nancy



More information about the Python-list mailing list