我有这个代码,我无法运行它,因为我收到此错误:"TypeError:'classobj'对象不可订阅",这是我的代码:
import cgi
import customerlib
form=cgi.FieldStorage
history = customerlib.find(form["f_name"].value,form["l_name"].value)
print "Content-type: text/html"
print
print """<html>
<head>
<title>Purchase history</title>
</head>
<body>
<h1>Purchase History</h1>"""
print "<p>you have a purchase history of:"
for i in history: "</p>"
print""" <body>
</html>"""
Run Code Online (Sandbox Code Playgroud)
我在此文件旁边有customerlib文件.知道怎么解决吗?
form=cgi.FieldStorage
Run Code Online (Sandbox Code Playgroud)
FieldStorage是一个类,而不是一个对象.您需要将其实例化以创建FieldStorage对象:
form=cgi.FieldStorage()
Run Code Online (Sandbox Code Playgroud)
它是错误的,form["f_name"]因为表单当前是类的别名FieldStorage,而不是类型的对象FieldStorage.通过实例化它,它正在做你认为它应该做的事情.
查看cgi模块文档,了解有关如何使用CGI模块的更多详细信息.
| 归档时间: |
|
| 查看次数: |
293 次 |
| 最近记录: |