【问题标题】:CherryPy: How to restrict a route to POST-onlyCherryPy:如何将路由限制为仅 POST
【发布时间】:2013-03-31 10:14:06
【问题描述】:

我有一个看起来像这样的网络表单:

<form action="/process_form/" method="post">
  <input type="text" name="login" value="login" />
  <input type="text" name="password" value="123" />
  <input type="submit" />
</form>

处理这个问题的python类是:

class Handle:
  @cherrypy.expose()
  #@cherrypy.tools.post <-- Is something like this possible
  def index(self, login=None):
    print(login)

在 CherryPy 中有没有办法将对 /process_form/ 的调用限制为 POST 方法?我的意思是如果用户键入http://www.example.com/process_form/ 他/她应该得到一个异常/错误或找不到页面?

【问题讨论】:

标签: python-3.x http-post cherrypy


【解决方案1】:

Allow tool 将引发 405。

@cherrypy.tools.allow(methods=['POST'])

【讨论】:

    猜你喜欢
    • 2023-02-08
    • 2015-11-23
    • 1970-01-01
    • 2013-12-27
    • 1970-01-01
    • 2019-08-16
    • 1970-01-01
    • 2017-11-27
    • 1970-01-01
    相关资源
    最近更新 更多