简体   繁体   English

如何将Flask默认的HTTP方法从GET更改为POST

[英]how to change flask default http method from GET to POST

当前Flask使用GET作为默认HTTP方法,是否有任何灵活的方法可以将所有app.route的默认方法更改为POST

The only way I can think to do this would be to run your own version of Flask that changes this code to default to a POST 我能想到的唯一方法是运行自己的Flask版本,将该代码更改为默认为POST

# if the methods are not given and the view_func object knows its
# methods we can use that instead.  If neither exists, we go with
# a tuple of only ``GET`` as default.
if methods is None:
    methods = getattr(view_func, 'methods', None) or ('GET',)

becomes... 变成...

# if the methods are not given and the view_func object knows its
# methods we can use that instead.  If neither exists, we go with
# a tuple of only ``GET`` as default.
if methods is None:
    methods = getattr(view_func, 'methods', None) or ('POST',)

Code: Lines 1184-1188 代码:1184-1188行

Though at this point it's probably just simpler to add a method declaration of POST to each route definition. 尽管此时,将POST的方法声明添加到每个路由定义可能更简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM