我一直在为我的一个项目在 Python Web 框架之间做出选择,我真的很喜欢 CherryPy 与其他框架相比的轻量级、灵活和简洁。我遇到的唯一问题是我找不到任何关于如何区分通过 GET 和 POST 发送的数据的文档。
例如,我不希望用户能够通过 GET 请求 (http://example.com/login?username=user&password=pass) 提供他们的登录凭证,但是,根据 CherryPy's tutorial ,所有数据都作为方法参数发送,无论它们作为什么 HTTP 方法发送。有什么方法可以说我只想要 POST 数据还是必须使用 MethodDispatcher ?
谢谢!
最佳答案
参见 the docs .
A string containing the HTTP method, such as "GET" or "POST". Set in the "run" phase.
看起来检查 cherrypy.request.method 是你想要做的。
关于python - 区分 CherryPy 中的 GET 和 POST 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5588887/