加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python-3.x – CherryPy:如何将路由限制为仅限POST

发布时间:2020-12-20 11:26:16 所属栏目:Python 来源:网络整理
导读:我有一个网页形式,看起来像: 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: @cher
我有一个网页形式,看起来像:

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

解决方法

Allow tool将提高405.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读