This is the file I'm trying to access the data from, guessAnswer.py:
#!/usr/bin/python
print 'content-type: text/html'
print
import cgi
import cgitb; cgitb.enable()
userAnswer = cgi.FieldStorage()
userAnswer['userAnswer'].value
So basically, I printed HTML from file1.py, and it is read successfully on the server.
print '''<br> <form action='guessAnswer.py'>
<input name="userAnswer">
</form>
</b> </center> </h2>'''
However, I can't seem to get the data inputted by the user at from guessAnswer.py, because file1.py is a python file.
How do I access the user data then? Or is this code fine and some other part of my program is causing the problem?
When I run the file in command prompt, at the end of the error, I get:
Traceback (most recent call last):
File "guessAnswer.py", line 115, in <module>
print '<center> <h1> Your guess is <b> ' + guessTestTakers(hw22.someHighSchool, userInput['userAnswer'].value) + '</b>
t;/h1> </center>'
File "C:\Python27\lib\cgi.py", line 540, in __getitem__
raise KeyError, key
KeyError: 'userAnswer'