flask 限定url的传参(flask 7)

2019-08-13 14:35:22 浏览数 (1)

from flask import Flask,request

app = Flask(name)

colors=['blue','white','red'] @app.route('/colors/<any(%s):color>' % str(colors)[1:-1]) def ca(color): return color

if name == 'main': app.run( host='0.0.0.0', port=8888, debug=True )

如果传参不是列表中的值,返回404

@app.route ( ’ / colors/<any (blue, white , red) : color> ’)

0 人点赞