我是 web.py
的新手我尝试制作一个简单的应用程序,在其中检索 HTML 文件并显示它。
这是我的完整代码:
import web
render = web.template.render('templates/')
urls = (
'/(.*)', 'index'
)
class index:
def GET(self):
return render.index()
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()
当我运行此命令时,我收到错误消息:
<class 'TypeError'>
at /GET() takes 1 positional argument but 2 were given
每当我向 GET 函数添加随机参数时,页面就能够运行,但其他情况下就不能运行。如果有人能指出这里出了什么问题,那就太好了。
最佳答案
(.*)
将用作第二个参数,更改您的代码
class index:
def GET(self, name):
return render.index(name)
和模板index.html
$def with (name)
<html>
<head>
<title>Hello $name</title>
</head>
<body>
Hello $name
</body>
</html>
现在尝试打开http://127.0.0.1:8080/John
关于python - GET() 采用 1 个位置参数,但已给出 2 个,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53348110/