是否可以在@ app.route中传递python列表来定义接受的路由?
我找不到办法:\
以下是我要做的事情:
ClientID purpose class
1 1215693 radio/tv bad
2 1215696 used car good
3 1215699 radio/tv good
4 1215702 radio/tv good
5 1215705 radio/tv good
6 1215708 repairs good
7 1215711 radio/tv good
8 1215714 new car good
9 1215717 domestic appliance good
10 1215720 furniture/equipment bad
我希望列表中的所有路由都重定向到相同的功能。
谢谢!
答案 0 :(得分:1)
您可以将参数从路径传递给函数,并检查它是否存在于列表中:
urilist = ["/log", "/login", "/loginexample"]
@app.route('/<urllist>', methods=['GET'])
def main(urllist):
if "/{}".format(urllist) in urilist:
return 'Hello World!'
return flask.render_template("error.html")#or whatever else you would do if urllist is not in urilist