2

for example the url is : http://localhost:5000/create/user/<int:id>

I want to check whether the user has passed the id parameter or not.

I have done this.

@app.route('/create/user/<int:id>')
def create_user(id=None):
    if id is None:
         return jsonify({'message':'Bad request'})

for example

  1. http://localhost:5000/create/user/23
  2. http://localhost:5000/create/user/

In the 1 url the user has provided the value of id=23 so we will procedd but in the url 2, the user has not provided any value for id parameter, so we will throw some kind of error.

I want to know, how to implement such functionality.

2 Answers2

0

In variable w will be stored Boolean value of your desired check.

url = http://localhost:5000/create/user/1234
id = 1234
w = str(id) in ''.join(url.split('http://localhost:5000/create/user/'))
Aleksander Ikleiw
  • 2,549
  • 1
  • 8
  • 26
0

You can use a positive look behind with a regex to do this:

(?<=user\/)\d+

This matches any number of digits preceeded by user/.