Python 如何在flask中检查变量参数是否在url中传递?
例如,url是:Python 如何在flask中检查变量参数是否在url中传递?,python,flask,restapi,dynamic-url,Python,Flask,Restapi,Dynamic Url,例如,url是:http://localhost:5000/create/user/ 我想检查用户是否已通过id参数 我已经这样做了 @app.route('/create/user/<int:id>') def create_user(id=None): if id is None: return jsonify({'message':'Bad request'}) @app.route(“/create/user/”) def create_用户(id
http://localhost:5000/create/user/
我想检查用户是否已通过id参数
我已经这样做了
@app.route('/create/user/<int:id>')
def create_user(id=None):
if id is None:
return jsonify({'message':'Bad request'})
@app.route(“/create/user/”)
def create_用户(id=None):
如果id为“无”:
返回jsonify({'message':'Bad request'})
比如说
http://localhost:5000/create/user/23
http://localhost:5000/create/user/
我想知道,如何实现这样的功能。在变量
w
中将存储所需检查的布尔值
url = http://localhost:5000/create/user/1234
id = 1234
w = str(id) in ''.join(url.split('http://localhost:5000/create/user/'))
您可以使用正则表达式的正向查找来执行此操作:
(?<=user\/)\d+
(?