gpt4 book ai didi

python - 可以将变量发送到 CherryPy 中的索引页吗?

转载 作者:太空宇宙 更新时间:2023-11-03 19:38:40 27 4
gpt4 key购买 nike

例如我想访问http://localhost:8080/?var=val或与 POST 类似,但我收到 500 服务器错误:

500 Internal Server Error

The server encountered an unexpected condition which prevented it from fulfilling the request.

Traceback (most recent call last): File "c:\python26\lib\site-packages\cherrypy\_cprequest.py", line 606, in respond   cherrypy.response.body = self.handler() File "c:\python26\lib\site-packages\cherrypy\_cpdispatch.py", line 25, in __call__   return self.callable(*self.args, **self.kwargs)TypeError: index() takes no arguments (1 given)

Powered by CherryPy 3.1.2

最佳答案

这绝对是可能的。

这是一个示例(改编自 the CherryPy tutorial ):

<form action="indexPostHandler" method="post">
<p>Enter a value:</p>
<input type="text" name="val" value=""/>
<p><input type="submit" value="Login"/></p>
</form>

并且,在索引中,您可以使用类似以下内容来处理请求:

class Root:
# create form here
def indexPostHandler(self, val=None):
# do something with val here
...

关于python - 可以将变量发送到 CherryPy 中的索引页吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1993565/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com