CherryPy:如何将路由限制为仅POST

时间:2013-03-31 10:14:06

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

我的网页表单如下:

<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/他/她应该得到异常/错误或找不到页面?

1 个答案:

答案 0 :(得分:8)

Allow tool将提升405。

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