首页 > 解决方案 > Flask url 重定向给出了意外的关键字参数异常

问题描述

我正在尝试使用烧瓶根据 URL 参数连接到不同的数据库

在将路线定义为

@app.route('/data_service/file/<string:db>/', methods=['GET','DELETE','POST','PUT'])
def file():

然而,烧瓶抱怨说

TypeError: file() got an unexpected keyword argument 'db'

恕我直言,这应该根据描述工作,例如https://pythonprogramming.net/flask-url-converters-tutorial/

标签: pythonflask

解决方案


我发现了错误

参数应该出现在函数中,在这种情况下,代码应该是

@app.route('/data_service/file/<string:db>/', methods=['GET','DELETE','POST','PUT'])
def file():

推荐阅读