473,321 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

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

Hi, Guys,
I am new to Python. I am trying to following the example on
http://www.modpython.org/live/curren...l/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
Jul 18 '05 #1
3 3634
On 27 Jul 2004, Nancy wrote:
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?


Your ISP should provide an SMTP server you can use: for me, it's
smtp.charter.net (being a Charter subscriber); it should be something
similar for yours. If your ISP doesn't provide SMTP, you can probably
find an open SMTP relay on the Internet somewhere, though I wouldn't
really recommend that if you can avoid it. Setting SMTP_SERVER to this
server and WEBMASTER to whichever e-mail address to which you want the
e-mail to be sent should be all you need.

Jul 18 '05 #2
Hi Nancy,

Please answer the following questions:

1) Do you have access to a web server? [yes / no]
2) Do you have access to a SMTP server? [yes / no]

If you answered "no" to any of the following questions above, this code
sample will not work for you. Why?

1) You must have access to a web server in order for the form to be
processed.
2) You must have access to an SMTP server in order to send e-mail on the
Internet. Without this, you are toast.

Byron
---

Nancy wrote:
Hi, Guys,
I am new to Python. I am trying to following the example on
http://www.modpython.org/live/curren...l/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

Jul 18 '05 #3
> 1) Do you have access to a web server? [yes / no]
2) Do you have access to a SMTP server? [yes / no]


For question 1, is YES, for question 2 is NO.

I know I cann't following this example. My question is if I don't
use SMTP server, is there any other way to handle HTML form? for
example php, ASP, java Applet can do it very well (by using some
functions or variables).

Thanks.

Nancy
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

29
by: Catalin | last post by:
Can Python replace PHP? Can I use a python program to make an interface to a mysql 4.X database? If that's possible where can I find a tutorial?
34
by: Erik Johnson | last post by:
This is somewhat a NEWBIE question... My company maintains a small RDBS driven website. We currently generate HTML using PHP. I've hacked a bit in Python, and generally think it is a rather...
1
by: Nancy | last post by:
Hi, I follow the Mod_python manual and try to let my form.py to handle html form. The form.html and form.py are copied from http://www.modpython.org/live/current/doc-html/tut-pub.html, after I...
3
by: Python_it | last post by:
I going to use the cgi-handler (mod_python): http://www.modpython.org/live/mod_python-3.2.2b/doc-html/hand-cgi.html If I test a simply py script it works code: =========== print...
6
by: Little | last post by:
I can't figure out how to build this type of program using the publisher handler. I have the following connected to the program SetHandler python-program PythonHandler mod_python.publisher...
12
by: vpr | last post by:
Hi All I want to build an Website using Apache / Python and MySQL. I dont want to spend to much time hacking html. I'm looking for some recommendations e.g. should I be using mod_python ?...
13
by: John Salerno | last post by:
I'm hoping someone can give me the basics for how to do very simple things with Python scripts from within my HTML. For example, I know that I can do this in PHP: <h1>Here is a header</h1>...
37
by: John Salerno | last post by:
I contacted my domain host about how Python is implemented on their server, and got this response: ------------------- Hello John, Please be informed that the implementation of python in our...
3
by: joe jacob | last post by:
I configured apache to execute python scripts using mod_python handler. I followed below mentioned steps to configure apache. 1. In http.conf I added <Directory...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.