当我在cgi.fieldstorage()类中使用getvalue()方法时,我有变量" name"在非类型中。简单地说,我无法对从表格中获得的价值做任何事情。我无法计算结果,也无法编辑结果。但它可以在html上显示。如何通过摆脱非类型来利用变量?
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'
test1.html:
<!DOCTYPE html>
<html>
<head>
<title>Test1</title>
</head>
<body>
<form action="http://localhost/cgi-bin/test2.py" method="get">
Name: <input type="text" name="name"> <br />
<input type="submit" value="Submit" />
</form>
</body>
</html>
test2.py:
import cgi, cgitb
form = cgi.FieldStorage()
your_name = form.getvalue('name')
your_name = 'hello, '+ your_name
print('Content-type:text/html')
print()
print('<html>')
print ('<head>')
print ('<title>CGI</title>')
print ('</head>')
print ('<body>')
print(your_name)
print ('</body>')
print ('</html>')