当我在视图函数中添加“ POST”作为方法时,不允许使用该方法

编程入门 行业动态 更新时间:2024-10-09 04:23:38
本文介绍了当我在视图函数中添加“ POST”作为方法时,不允许使用该方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我所有的视图函数中,如果我使用 methods = ['POST'],例如:

In all of my view functions if i 'methods=['POST'] for example:

@app.route( '/file', methods=['POST'] )

我收到错误:

Error: 405 Method Not Allowed Sorry, the requested URL 'superhost.gr/downloads/file' caused an error:

为什么Bottle给我这个错误消息?

Why Bottle gives me this error message?

推荐答案

我猜想在尝试获取视图(GET)时会出错。那是您只允许POST的结果。

I'd guess you get error when trying to get the view (GET). And that is result of your only allowing POST.

您应该拥有

@app.route( '/file', method=['POST', 'GET'] )

或单独的处理程序

@app.route( '/file', method=['GET'] )

更新:您复制的示例中似乎有一个错字。 方法应该是方法。

Update: looks like there was a typo in your example that I copied over. 'methods' should be 'method'.

Update2:以下是一个有效的示例:

Update2: Below is a working example:

from bottle import Bottle, run app = Bottle() @app.route('/file', method=['GET', 'POST']) def file(): return "Hello!" run(app, host='localhost', port=8080)

更多推荐

当我在视图函数中添加“ POST”作为方法时,不允许使用该方法

本文发布于:2023-10-10 18:31:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1479386.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方法   我在   不允许   视图   函数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!