Python Language Flask Routing URLs

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!


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

Got any Python Language Question?