Python 如何在flask中检查变量参数是否在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

例如,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=None):
如果id为“无”:
返回jsonify({'message':'Bad request'})
比如说

  • http://localhost:5000/create/user/23
  • http://localhost:5000/create/user/
  • 1url中,用户提供了id=23的值,因此我们将继续处理,但在url2中,用户没有提供id参数的任何值,因此我们将抛出某种错误


    我想知道,如何实现这样的功能。

    在变量
    w
    中将存储所需检查的
    布尔值

    url = http://localhost:5000/create/user/1234
    id = 1234
    w = str(id) in ''.join(url.split('http://localhost:5000/create/user/'))
    

    您可以使用正则表达式的正向查找来执行此操作:

    (?<=user\/)\d+
    
    (?