Problem with Python CGI Script Output

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chintan85
    New Member
    • Jun 2010
    • 33

    Problem with Python CGI Script Output

    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:
    Code:
    <form method="POST" action="/test/simple1.py">
    <p>Your First name: <input type="text" name="firstname"> 
    <p>Your Last name: <input type="text" name="lastname">
    <p>Click here to submit form: <input type="submit" value="Yeah!">
    <input type="hidden" name="session" value="1f9a2">
     </form>
    this is python script
    Code:
    #!/usr/bin/python
    
    # Import modules for CGI handling 
    import cgi 
    import cgitb;
    cgitb.enable()
    
    # Create instance of FieldStorage 
    form = cgi.FieldStorage() 
    
    # Get data from fields
    first_name = form.getvalue('firstname')
    last_name  = form.getvalue('lastname')
    
    #print "Content-type:text/htmlnn"
    print "Content-type:text/html\n\n"
    print "<html>"
    print "<head>"
    print "<title>Hello - Second CGI Program</title>"
    
    print "</head>"
    print "<body>"
    print "<h2>Hello %s %s</h2>" % (first_name, last_name)
    print "</body>"
    print "</html>"
  • Glenton
    Recognized Expert Contributor
    • Nov 2008
    • 391

    #2
    Can you tell us what error messages you get?

    Comment

    • chintan85
      New Member
      • Jun 2010
      • 33

      #3
      Originally posted by Glenton
      Can you tell us what error messages you get?
      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.

      Comment

      • Glenton
        Recognized Expert Contributor
        • Nov 2008
        • 391

        #4
        Try changing lines 12 to 14 from this:
        Code:
        # Get data from fields
        first_name = form.getvalue('firstname')
        last_name  = form.getvalue('lastname')
        to this:
        Code:
        # Get data from fields
        first_name = form['firstname'].value
        last_name  = form['lastname'].value

        Comment

        • chintan85
          New Member
          • Jun 2010
          • 33

          #5
          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.

          Code:
          </Directory>
          <IfModule python_module>
              <Directory "/xampp/htdocs/test">
                  AddHandler mod_python .py 
                  PythonHandler mod_python.publisher
                  PythonDebug On
              </Directory>
          
              <Directory "/xampp/htdocs/test">
                  SetHandler mod_python
                  PythonHandler mod_python.cgihandler
              </Directory>
          </IfModule>
          Do you think the problem due to this ?

          Comment

          Working...