473,387 Members | 1,722 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,387 software developers and data experts.

Simple python + html + from --> to python script

Hello All,

I am trying to get information from a form and send it to a python
script without success..
Here is my objective:

User enters data in form --form send variables to python script -->
script runs and output result.

the form code

<form method="post" action="/cgi-bin/script.py" name="coord">Entre com
os dados <input name="data1"><br>

Entre com os dados <input name="data2"><br>
Vai magraum <button name="submete"></button></form>

In my script.py

What I should have to print
something like

Hello the data1 + data 2 = ....

?

Maybe I am stumbling in something very simple, but I cannot find some
working example, and I am totally confused...
Thanks in advance

Oct 24 '06 #1
8 1861
flit wrote:
Hello All,

I am trying to get information from a form and send it to a python
script without success..
Here is my objective:

User enters data in form --form send variables to python script -->
script runs and output result.

the form code

<form method="post" action="/cgi-bin/script.py" name="coord">Entre com
os dados <input name="data1"><br>

Entre com os dados <input name="data2"><br>
Vai magraum <button name="submete"></button></form>

In my script.py

What I should have to print
something like

Hello the data1 + data 2 = ....

?

Maybe I am stumbling in something very simple, but I cannot find some
working example, and I am totally confused...
Thanks in advance
Untested, without error checking. Caveat emptor:

import cgi
import cgitb; cgitb.enable() # optional error handling

form = cgi.FieldStorage()

d1 = form["data1"].value
d2 = form["data2"].value

print """\
Content-type: text/plain

Hello: the data were: %s and %s""" % (d1, d2)

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Oct 24 '06 #2
Man....
Very thanks...
I really try to find some source of good and simple and nothing..
Many thanks you are a great help!

Steve Holden wrote:
flit wrote:
Hello All,

I am trying to get information from a form and send it to a python
script without success..
Here is my objective:

User enters data in form --form send variables to python script -->
script runs and output result.

the form code

<form method="post" action="/cgi-bin/script.py" name="coord">Entre com
os dados <input name="data1"><br>

Entre com os dados <input name="data2"><br>
Vai magraum <button name="submete"></button></form>

In my script.py

What I should have to print
something like

Hello the data1 + data 2 = ....

?

Maybe I am stumbling in something very simple, but I cannot find some
working example, and I am totally confused...
Thanks in advance
Untested, without error checking. Caveat emptor:

import cgi
import cgitb; cgitb.enable() # optional error handling

form = cgi.FieldStorage()

d1 = form["data1"].value
d2 = form["data2"].value

print """\
Content-type: text/plain

Hello: the data were: %s and %s""" % (d1, d2)

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
Oct 24 '06 #3
A good starting place would be the documentation on python.org.

In this case, the python library reference would have been helpful:

http://docs.python.org/lib/lib.html

Cheers,
Cliff
flit wrote:
Man....
Very thanks...
I really try to find some source of good and simple and nothing..
Many thanks you are a great help!

Steve Holden wrote:
>flit wrote:
>>Hello All,

I am trying to get information from a form and send it to a python
script without success..
Here is my objective:

User enters data in form --form send variables to python script -->
script runs and output result.

the form code

<form method="post" action="/cgi-bin/script.py" name="coord">Entre com
os dados <input name="data1"><br>

Entre com os dados <input name="data2"><br>
Vai magraum <button name="submete"></button></form>

In my script.py

What I should have to print
something like

Hello the data1 + data 2 = ....

?

Maybe I am stumbling in something very simple, but I cannot find some
working example, and I am totally confused...
Thanks in advance
Untested, without error checking. Caveat emptor:

import cgi
import cgitb; cgitb.enable() # optional error handling

form = cgi.FieldStorage()

d1 = form["data1"].value
d2 = form["data2"].value

print """\
Content-type: text/plain

Hello: the data were: %s and %s""" % (d1, d2)

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
Oct 24 '06 #4
Sorry but for a totally newbie the lib doccumentation doesnt help..
The target audience for the docs are for "grown ups" programmers..
I think I will do some tutorial, in baby steps...

J. Clifford Dyer wrote:
A good starting place would be the documentation on python.org.

In this case, the python library reference would have been helpful:

http://docs.python.org/lib/lib.html

Cheers,
Cliff
flit wrote:
Man....
Very thanks...
I really try to find some source of good and simple and nothing..
Many thanks you are a great help!

Steve Holden wrote:
flit wrote:
Hello All,

I am trying to get information from a form and send it to a python
script without success..
Here is my objective:

User enters data in form --form send variables to python script -->
script runs and output result.

the form code

<form method="post" action="/cgi-bin/script.py" name="coord">Entre com
os dados <input name="data1"><br>

Entre com os dados <input name="data2"><br>
Vai magraum <button name="submete"></button></form>

In my script.py

What I should have to print
something like

Hello the data1 + data 2 = ....

?

Maybe I am stumbling in something very simple, but I cannot find some
working example, and I am totally confused...
Thanks in advance

Untested, without error checking. Caveat emptor:

import cgi
import cgitb; cgitb.enable() # optional error handling

form = cgi.FieldStorage()

d1 = form["data1"].value
d2 = form["data2"].value

print """\
Content-type: text/plain

Hello: the data were: %s and %s""" % (d1, d2)

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
Oct 24 '06 #5
flit a écrit :
Hello All,

I am trying to get information from a form and send it to a python
script without success..
Here is my objective:

User enters data in form --form send variables to python script -->
script runs and output result.
<OT topic="HTTP">
If the script has side-effects (adding/updating/deleting database
records, writing files, etc), the script should not "output results",
but redirect to another url where the user can see these results.

Else - if the script doesn't have side-effects (ie :a search form, ...),
then the HTTP method should be "GET", not "POST".
</OT>
the form code

<form method="post" action="/cgi-bin/script.py" name="coord">Entre com
os dados <input name="data1"><br>

Entre com os dados <input name="data2"><br>
Vai magraum <button name="submete"></button></form>
<OT topic="HTML">
button elements don't submit the form - they in fact don't do anything
unless you attach behaviour to them with javascript. What you want here
is an input type='submit'.

Also, the "button" tag doesn't require a end tag.

<form method="POST" action="/cgi-bin/script.py" name="coord">
<label for="data1">Entre com os dados</label>
<input type="text" name="data1" id="data1"><br>

<label for="data2">Entre com os dados </label>
<input type="text" name="data2" id="data2"><br>
Vai magraum <input type="submit" name="submete">
</form>
</OT>

(cf Steve's answer and the cgi module's doc for your problem)
Oct 24 '06 #6
Bruno Desthuilliers wrote:
flit a écrit :
>>Hello All,

I am trying to get information from a form and send it to a python
script without success..
Here is my objective:

User enters data in form --form send variables to python script -->
script runs and output result.


<OT topic="HTTP">
If the script has side-effects (adding/updating/deleting database
records, writing files, etc), the script should not "output results",
but redirect to another url where the user can see these results.

Else - if the script doesn't have side-effects (ie :a search form, ...),
then the HTTP method should be "GET", not "POST".
</OT>
>>the form code

<form method="post" action="/cgi-bin/script.py" name="coord">Entre com
os dados <input name="data1"><br>

Entre com os dados <input name="data2"><br>
Vai magraum <button name="submete"></button></form>


<OT topic="HTML">
button elements don't submit the form - they in fact don't do anything
unless you attach behaviour to them with javascript. What you want here
is an input type='submit'.

Also, the "button" tag doesn't require a end tag.

<form method="POST" action="/cgi-bin/script.py" name="coord">
<label for="data1">Entre com os dados</label>
<input type="text" name="data1" id="data1"><br>

<label for="data2">Entre com os dados </label>
<input type="text" name="data2" id="data2"><br>
Vai magraum <input type="submit" name="submete">
</form>
</OT>

(cf Steve's answer and the cgi module's doc for your problem)
So what problem were you talking about?

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Oct 24 '06 #7
Bruno Desthuilliers wrote:
(snip)
<OT topic="HTML">
(snip)
Also, the "button" tag doesn't require a end tag.
oops ! Sorry, your syntax was ok - button elements actually requires the
end tag.

my bad :(
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Oct 25 '06 #8
Good point. I forget sometimes, because that's how I learned, but I
came in with some background in other scripting languages, so I guess I
knew what I was looking for.

Thanks.

Cliff

flit wrote:
Sorry but for a totally newbie the lib doccumentation doesnt help..
The target audience for the docs are for "grown ups" programmers..
I think I will do some tutorial, in baby steps...

J. Clifford Dyer wrote:
>A good starting place would be the documentation on python.org.

In this case, the python library reference would have been helpful:

http://docs.python.org/lib/lib.html

Cheers,
Cliff
Oct 25 '06 #9

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

Similar topics

0
by: Irmen de Jong | last post by:
QOTW: "To make the instructions even friendlier it would also help if 'but Whatever You Do DON'T UNZIP THE FREAKIN' THING - This Means YOU John Latter!' were in large, bold, and underlined type. ...
0
by: Raymond Hettinger | last post by:
QOTW: "Python seems to encourage and reward incremental effort, and it leads one to explore extensions and improvements to programs because the language makes it relatively easy to see how to do...
1
by: Raymond Hettinger | last post by:
QOTW: "the DOM API is designed for consultants, not for humans or computers" -- Fredrik Lundh giving solace to a confused DOM API user QOTW: "Python enjoys making tradeoffs that drive *someone*...
0
by: Cameron Laird | last post by:
QOTW: praise than which there is no higher: "I like the Python Cookbook, edited by Alex Martelli and David Ascher. I keep that one in my bathroom." Terry Carroll "e needed something more...
0
by: Cameron Laird | last post by:
QOTW: "Well, to do what I've done so far in Java would have taken at least 5 and probably more like 10 times the code I've written. A simple yet decent TCP chat server in about 30 lines of code...
0
by: John J Lee | last post by:
QOTW: "...simple genexps will work fine anyway almost all the time, so it doesn't appear to matter much that devious uses will have nightmarish semantics." -- Tim Peters on Generator Expressions ...
1
by: Craig Ringer | last post by:
QOTW: "Such infrastructure building is in fact fun and instructive -- as long as you don't fall into the trap of *using* such complications in production code, where Python's simplicity rules;-)."...
0
by: Simon Brunning | last post by:
QOTW: "" - John Machin, snipping a section of Perl code. "What sort of programmer are you? If it works on your computer, it's done, ship it!" - Grant Edwards Guido invites us to comment on...
2
by: Frank Millman | last post by:
Hi all I need to pass data between a server program and a client program, both written in Python. My first thought was to use xml. The server builds up an xml string, without using any xml...
0
by: Cameron Laird | last post by:
QOTW: "Dictionaries are one of the most useful things in Python. Make sure you know how to take adavantage of them..." - Jeremy Sanders "Python has consistently failed to disappoint me." - Tal...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.