如何选择将哪个参数传递给 Flask 中的多装饰路由?

How can I choose which parameter to pass to a multidecorated route in Flask?

我正在使用以下代码:

@api.route('/akilo/<a>/<b>/')
@api.route('/akilo/<c>/')
class Akilo(Resource):
    def get(self, a, b, c):
        if a and b:
            return a + b
        else:
            return c

根据我使用的参数从同一资源获得不同的响应

当我发出请求时:

/select/akilo/bom/dia/

我收到以下错误:

TypeError: get() takes exactly 4 arguments (3 given)

你能帮帮我吗?

您需要更改 get 的签名以使 abc 可选。

def get(a=None, b=None, c=None):

或者您需要为路由中未使用的那些提供默认值。

@api.route('/akilo/<a>/<b>/', defaults={'c': None})
@api.route('/akilo/<c>/', defaults={'a': None, 'b': None}) t