当前flask使用 GET 作为默认HTTP方法,是否有任何灵活的方法可以将所有app.route的默认方法更改为 POST ?
答案 0 :(得分:1)
我认为要执行此操作的唯一方法是运行自己的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',)
成为...
# 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',)
尽管在这一点上,将POST的方法声明添加到每个路由定义中可能更简单。