我正在学习 python,所以我从一本书中得到了这个练习:这是一个 html 表单:
<html>
<body>
<form method=POST action="cgi-bin/cgi101.py">
<P><b>Enter your name:</b>
<P><input type="text name=user" />
<P><input type="submit" />
</form>
</body>
</html>
这是要调用的脚本:
#!/usr/bin/python3
import cgi
form = cgi.FieldStorage()
# parse form data
print('Content-type: text/html\n')
# hdr plus blank line
print('<title>Reply Page</title>')
# html reply page
if not 'user' in form:
print('<h1>Who are you?</h1>')
else:
print('<h1>Hello <i>%s</i>!</h1>' % cgi.escape(form['user'].value))
按照逻辑,如果我输入用户,它必须打印