pythonformsflaskhttp-redirectdynamic-url

Creating multiple and dynamic routes for one function in Flask | Python


I'm trying to create a verification program where a user goes to a URL and then they get verified.

For each user, I want to create a new url example.com/verificationUser, for user 2 it'd be example.com/verificationUser2.

How can I set a "dynamic" app route in Flask?

@app_route(dynamic)
def do_this():
   return "hello"

I want the same function to run on a new app route. so both example.com/verificationUser and example.com/verificationUser2 get returned hello


Solution

  • That's how you do it

    @app.route('/verification/<name>')
    def profile(name):
        return f'Hello {name}'