internet form handling

Reply

Join Date: Mar 2005
Posts: 192
Reputation: stupidenator is an unknown quantity at this point 
Solved Threads: 4
stupidenator's Avatar
stupidenator stupidenator is offline Offline
Junior Poster

internet form handling

 
0
  #1
Jun 24th, 2005
Hey all,
I am very new to python, but I hear that it can be used to handle web forms. Does anybody know of where I can find a good tutorial on how to create something that will handle form input? Thanks in advance.
-Nick
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 39
Reputation: nephish is an unknown quantity at this point 
Solved Threads: 0
nephish nephish is offline Offline
Light Poster

Re: internet form handling

 
0
  #2
Jun 24th, 2005
what you want to look at is the cgi module.
go here
http://gnosis.cx/publish/programming...in_python.html
or here
http://wiki.python.org/moin/CgiScripts

i use only python in my cgi , just because i dig python.
hope this helps
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 192
Reputation: stupidenator is an unknown quantity at this point 
Solved Threads: 4
stupidenator's Avatar
stupidenator stupidenator is offline Offline
Junior Poster

Re: internet form handling

 
0
  #3
Jun 24th, 2005
Thanks a lot! This should help out a lot.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 192
Reputation: stupidenator is an unknown quantity at this point 
Solved Threads: 4
stupidenator's Avatar
stupidenator stupidenator is offline Offline
Junior Poster

Re: internet form handling

 
0
  #4
Jun 25th, 2005
One more quick question...
How should the HTML look? I can't really figure out how to get the form to call the python program.
Thanks again in advance!
-Nick
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 39
Reputation: nephish is an unknown quantity at this point 
Solved Threads: 0
nephish nephish is offline Offline
Light Poster

Re: internet form handling

 
0
  #5
Jun 25th, 2005
use a wysiwyg editor like mozilla-composer or nvu. (free downloads too!)

they have little buttons, forms, text imput, drop down lists, etc... stuff that you can choose from to create the form. it helps you out until you learn more of html.

hope this helps
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 192
Reputation: stupidenator is an unknown quantity at this point 
Solved Threads: 4
stupidenator's Avatar
stupidenator stupidenator is offline Offline
Junior Poster

Re: internet form handling

 
0
  #6
Jun 25th, 2005
Thanks for the reply. I am pretty good at html, and I know how to make a form. What I'm struggling with is how to make the form talk to the python program. I can't seem to get it to work.
-Nick
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 39
Reputation: nephish is an unknown quantity at this point 
Solved Threads: 0
nephish nephish is offline Offline
Light Poster

Re: internet form handling

 
0
  #7
Jun 25th, 2005
try this....

here is a simple form.....

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <meta content="text/html; charset=ISO-8859-1"
  5. http-equiv="content-type">
  6. <title>Admin Login</title>
  7. </head>
  8. <body>
  9. <big><big>Login
  10. Here<br>
  11. <br>
  12. </big></big>
  13. <form action="/cgi-bin/Login.py" name="LoginForm"><big>Administration
  14. Login<br>
  15. User Name<br>
  16. <input name="UserName"><br>
  17. <br>
  18. <br>
  19. Password<br>
  20. <input name="PassWord"><br>
  21. </big><br>
  22. <br>
  23. <br>
  24. <input type="submit">
  25. <br>
  26. </form>
  27. &nbsp;__&nbsp;<br>
  28. </body>
  29. </html>

and the script that it passes info to in the cgi-bin
called login.py

  1. #!/usr/bin/python
  2. import cgi
  3. import cgitb; cgitb.enable()
  4. # get the info from the html form
  5. form = cgi.FieldStorage()
  6. #set up the html stuff
  7. reshtml = """Content-Type: text/html\n
  8. <html>
  9. <head><title>Security Precaution</title></head>
  10. <body>
  11. """
  12.  
  13. print reshtml
  14.  
  15. User = form['UserName'].value
  16. Pass = form['PassWord'].value
  17.  
  18. if User == 'john' and Pass == 'jacob':
  19. print '<big><big>Welcome'
  20. print 'mr. Jingleheimerschmidt !</big></big><br>'
  21. print '<br>'
  22. else:
  23. print 'Sorry, incorrect user name or password'
  24. print '</body>'
  25. print '</html>'

if you are using Linux, remember to make the login.py
script executable
chmod a+x /whatever/the/path/is/to/your/cgi-bin/login.py

let me know how it works.
also. if it does not work, lemme know some other stuff
what web server you are using.....
operating system.....
etc... what ever you think may help diagnose.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 192
Reputation: stupidenator is an unknown quantity at this point 
Solved Threads: 4
stupidenator's Avatar
stupidenator stupidenator is offline Offline
Junior Poster

Re: internet form handling

 
0
  #8
Jun 25th, 2005
I tried running what you sent me and it didn't seem to work. When I tell python to print something (such as all the html code along with the form data) where is it printing it to? I'm also very new to networking and things like that. Would I have to upload my python code and html file to my web site for it to run properly, or will it run right just straight off of my computer?(I have Windows XP with python installed). When I upload it to my web site, I believe it is an apache server. Thanks for your help in advance.
-Nick

Also, the web site says that it supports scripting languages such as perl, php, etc.. but it does not exactly say that it supports python. Does it need to say that? The web site was purchased from Lonex <www.lonex.com>
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 39
Reputation: nephish is an unknown quantity at this point 
Solved Threads: 0
nephish nephish is offline Offline
Light Poster

Re: internet form handling

 
0
  #9
Jun 25th, 2005
ok
first off, many web hosts support scripting languages, but as they include php, perl, etc.. many do not support python.
the good news is...
you can host the site yourself.
apache is available for windows and they have great documentation and support.
heck, i will even host your site (i am hosting four sites now) if you are not going to get more than a thousand hits/day.

what i am saying is.... its easy... seems intimidating at first, but all things technical do. what you need is python, apache and the mod_python module. you edit the configuration file to have apache start the mod_python module when apache starts. put your scripts in a folder called cgi-bin (usually) look for a line in the apache configuration file called Script-Alias. this is also where the scripts would go if you upload them to a host. almost always not the same folder where the html stuff goes.
and, yeah, the scripts whatever.py has to be on the server because they are server side scripts. server side means that all the data process is done at the server and the results are posted to the web page.
when you call print, and you are printing html, it is printing to the web browser.
in the two scripts i posted, the html form passes data to the python script, the python script takes that info (username and password) and creates a webpage that
does something based on whether or not the username and password match what the script says. the base line is that the python script actually creates html code.

another reason it did not work is the first line of the scrip.
The one that starts with a pound-bang (#!)

  1. #!/usr/bin/python

That is a linux thing.

check this link for how to set that line up correctly i think its C:\python24
but i am not sure. i stupidly assumed that you use linux because most servers use either linux or unix

check here for windows

check the apache docs for how to set up their server on your windows box. apache runs on windows too. but i am not very familliar with it. i think you
must have it installed and running to execute a cgi python script from your
own computer. maybe there is another freeware app out there,, a light server that may do you better . even if you dont host the site yourself, you can use a webserver on your home computer to test out your scripts because it is much easier to debug and re-arrange right there and then upload when you know it does exactly what you want.

Keep me posted on how its working out. if i dont know the answer, i can find it somewhere.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 39
Reputation: nephish is an unknown quantity at this point 
Solved Threads: 0
nephish nephish is offline Offline
Light Poster

Re: internet form handling

 
0
  #10
Jun 29th, 2005
Hey there, how is your project comming along ?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC