473,467 Members | 1,954 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem with Python CGI Script Output

33 New Member
Hi,
I trying to create web application that queries the database.The input from the form is not acquired by the variable and so correct output is not displayed.

May be my path is not correct - usr/bin/python..
can u suggest me...I m in dire need of help.

This is my HTML code:
Expand|Select|Wrap|Line Numbers
  1. <form method="POST" action="/test/simple1.py">
  2. <p>Your First name: <input type="text" name="firstname"> 
  3. <p>Your Last name: <input type="text" name="lastname">
  4. <p>Click here to submit form: <input type="submit" value="Yeah!">
  5. <input type="hidden" name="session" value="1f9a2">
  6.  </form>
  7.  
this is python script
Expand|Select|Wrap|Line Numbers
  1.  
  2. #!/usr/bin/python
  3.  
  4. # Import modules for CGI handling 
  5. import cgi 
  6. import cgitb;
  7. cgitb.enable()
  8.  
  9. # Create instance of FieldStorage 
  10. form = cgi.FieldStorage() 
  11.  
  12. # Get data from fields
  13. first_name = form.getvalue('firstname')
  14. last_name  = form.getvalue('lastname')
  15.  
  16. #print "Content-type:text/htmlnn"
  17. print "Content-type:text/html\n\n"
  18. print "<html>"
  19. print "<head>"
  20. print "<title>Hello - Second CGI Program</title>"
  21.  
  22. print "</head>"
  23. print "<body>"
  24. print "<h2>Hello %s %s</h2>" % (first_name, last_name)
  25. print "</body>"
  26. print "</html>"
  27.  
Jun 10 '10 #1
4 1997
Glenton
391 Recognized Expert Contributor
Can you tell us what error messages you get?
Jun 15 '10 #2
chintan85
33 New Member
@Glenton
Actually variable first_name and last_name in script is not taking the value from form i.e inputs.
So my output is Hello None None.. Even if I enter my the names.
Jun 15 '10 #3
Glenton
391 Recognized Expert Contributor
Try changing lines 12 to 14 from this:
Expand|Select|Wrap|Line Numbers
  1. # Get data from fields
  2. first_name = form.getvalue('firstname')
  3. last_name  = form.getvalue('lastname')
to this:
Expand|Select|Wrap|Line Numbers
  1. # Get data from fields
  2. first_name = form['firstname'].value
  3. last_name  = form['lastname'].value
Jun 16 '10 #4
chintan85
33 New Member
I tried but not working.
I think there is something wrong with (xampp)apache configuration.

I have used mod_python and made changes to http.conf files.
also i have added publisher handler and cgi handler.

Expand|Select|Wrap|Line Numbers
  1. </Directory>
  2. <IfModule python_module>
  3.     <Directory "/xampp/htdocs/test">
  4.         AddHandler mod_python .py 
  5.         PythonHandler mod_python.publisher
  6.         PythonDebug On
  7.     </Directory>
  8.  
  9.     <Directory "/xampp/htdocs/test">
  10.         SetHandler mod_python
  11.         PythonHandler mod_python.cgihandler
  12.     </Directory>
  13. </IfModule>
  14.  
Do you think the problem due to this ?
Jun 16 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: John Fitzsimons | last post by:
Hi, I want to search an ordered text file and list web links such as : Input like ; A Folder Freeware ftp://ftp.eunet.bg/pub/simtelnet
2
by: ben moretti | last post by:
hi i'm learning python, and one area i'd use it for is data management in scientific computing. in the case i've tried i want to reformat a data file from a normalised list to a matrix with some...
3
by: SeeBelow | last post by:
I have not been able to find a simple way to have a python script execute an MS-DOS program repeatedly. execv(), for example, won't run it more than once. I have been using many lines of a .bat...
1
by: M.N.A.Smadi | last post by:
hi; how can i do the following: 1- run a C program from a python script 2- pass that C program an argument 3- Read the out of the program into a buffer that is local to the script thanks...
1
by: muttu2244 | last post by:
Hi everybody I have couple of questions, 1) How can i refresh my desktop window(wallpaper), using the python script, after pasting some data on the desktop. 2) How can i run an exe file...
6
by: tatamata | last post by:
Hello. How can I run some Python script within C# program? Thanks, Zlatko
8
by: flit | last post by:
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...
14
by: nsamad | last post by:
Hi All, Is there anyone using python script to programm the Telit GM862-GPS module?? I am a newbie in using python. I am developing an application in which i have to open a GPRS connection and...
12
by: adamurbas | last post by:
ya so im pretty much a newb to this whole python thing... its pretty cool but i just started today and im already having trouble. i started to use a tutorial that i found somewhere and i followed...
1
by: tinnews | last post by:
I'm running a python script via the apache ExtFilterDefine directive, it works basically as expected *except* that when I change the script apache/firefox continue to run the old version of the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.