Flask URLs

Part of Flask series.

Very simply, you can define a URL for your web app like this:

@app.route('/user/<username>')
def show_user_profile(username):
    # show the user profile for that user
    return ’User %s’ % username

Or like this:

def show_user_profile(username):
    # show the user profile for that user
    return ’User %s’ % username
app.add_url_rule('/user/<username>', 'show_user_profile', show_user_profile)

Note that the function name becomes the endpoint name. Endpoints are a way to uniquely identify URLs for rules purposes.