473,221 Members | 2,186 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,221 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 1852
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.