Python Language Routing URLs


With Flask, URL routing is traditionally done using decorators. These decorators can be used for static routing, as well as routing URLs with parameters. For the following example, imagine this Flask script is running the website

def index():
    return "You went to"

def about():
    return "You went to"

    return "You went to"

With that last route, you can see that given a URL with /users/ and the profile name, we could return a profile. Since it would be horribly inefficient and messy to include a @app.route() for every user, Flask offers to take parameters from the URL:

def profile(username):
    return "Welcome to the profile of " + username


def storefronts(city):
    if city in cities:
        return "Yes! We are located in " + city
        return "No. We are not located in " + city