我试图创建一个Python CGI脚本的HTML表单。我不明白蟒蛇`打印“”“'
script_name=os.environ.get('SCRIPT_NAME', '')
form = cgi.FieldStorage()
message = form.getvalue("message", "(no message)")
print """
<p>Previous message: %s</p>
<p>form
<form method="post" action="%s">
<p>message: <input type="text" name="message"/></p>
</form>
</body>
</html>
""" % cgi.escape(message), script_name
以上当然是行不通的。我是假的印象是, 整个print """ blah blah %s ...""" % string_var
工作像C的printf
功能 那么,要我想在这里做
我在浏览器中收到此错误信息:?
Traceback (most recent call last):
File "/usr/lib/cgi-bin/hello.py", line 45, in <module>
""" % cgi.escape(message), script_name
TypeError: not enough arguments for format string
居然会发生什么?你有错误信息吗?如果是这样,你能把它展示给我们吗? – user2357112
将括号内的格式化参数包装在内:) – mhlester
如果没有括号,Python会认为您想要打印两样东西:一个格式参数为单个字符串,另一个为第二个变量。 – jayelm