蟒蛇在线形式(例如反馈)不能正常工作

问题描述:

我正在学习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)) 

通过,如果我输入用户的逻辑,必须打印

你好用户

。但它给了

你是谁?改为

。这意味着脚本不会在表单中看到用户。为什么? cgi/py脚本允许在apache中用于cgi-bin /。

您在这里有一个错字:

<input type="text name=user" /> 

这实际上应该是这样的:

<input type="text" name="user" /> 

类型和名称都在输入HTML标签中的每个属性。他们将永远在的形式是:

<sometag attribute1="a thing" attribute2="another thing" /> 

请注意引号和等号的位置。语法突出显示的优秀文本编辑器将帮助您的眼球更清楚地看到这一点。

+0

史诗般的失败......感冒后我不应再编码......谢谢! – boldnik