0

I've created a HTML page with forms, which takes a name and password and passes it to a Python Script which is supposed to print the persons name with a welcome message. However, after i POST the values, i'm just getting the Python code displayed in the browser and not the welcome message. I have stored the html file and python file in the cgi-bin folder under Apache 2.2. If i just run a simple hello world python script in the browser, the "Hello World" message is being displayed. I'm using WinXP, Python 2.5, Apache 2.2. the code that i'm trying to run is the following:

#!c:\python25\python.exe
import cgi
import cgitb; cgitb.enable()
form = cgi.FieldStorage()
reshtml = """Content-Type: text/html\n
<html>
 <head><title>Security Precaution</title></head>
 <body>
 """

print reshtml 

User = form['UserName'].value
Pass = form['PassWord'].value

if User == 'Gold' and Pass == 'finger':
    print '<big><big>Welcome'
    print 'mr. Goldfinger !</big></big><br>'
    print '<br>'
else:
    print 'Sorry, incorrect user name or password' 
    print '</body>'
print '</html>'

The answer to it might be very obvious, but its completely escaping me. I'm very new to Python so any help would be greatly appreciated.

Thanks.

1
  • 1
    Why aren't you using mod_wsgi or a proper web framework? Commented Aug 21, 2009 at 10:37

2 Answers 2

1

This

i'm just getting the Python code displayed in the browser

sounds like CGI handling with Apache and Python is not configured correctly.

You can narrow the test case by passing UserName and PassWord as GET parameters:

http://example.com/cgi-bin/my-script.py?UserName=Foo&PassWord=bar

What happens if you do this?

Sign up to request clarification or add additional context in comments.

Comments

0

You may have to extract the field values like this

User = form.getfirst('UserName')
Pass = form.getfirst('PassWord')

I know, it's strange.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.