Recall & Review
beginner
What is the purpose of the
@app.route decorator in Flask?The
@app.route decorator tells Flask which URL should trigger a specific function. It connects a web address to the code that runs when that address is visited.Click to reveal answer
beginner
How do you define a route for the home page using
@app.route?You use
@app.route('/') above a function. This means when someone visits the root URL (like 'http://localhost:5000/'), Flask runs that function.Click to reveal answer
intermediate
Can
@app.route handle different HTTP methods? How?Yes. You can add the
methods argument like @app.route('/path', methods=['GET', 'POST']) to tell Flask which HTTP methods the route accepts.Click to reveal answer
intermediate
What happens if two functions have the same route with
@app.route?Flask will use the last function defined for that route, overwriting the previous one. This can cause unexpected behavior, so routes should be unique.
Click to reveal answer
beginner
How can you capture a variable part of the URL using
@app.route?You use angle brackets in the route like
@app.route('/user/<username>'). Flask passes the value in the URL to the function as an argument.Click to reveal answer
What does
@app.route('/about') do in a Flask app?✗ Incorrect
The route decorator connects the URL '/about' to a function that Flask runs when that URL is accessed.
How do you allow a route to accept both GET and POST requests?
✗ Incorrect
You specify allowed HTTP methods by adding the methods argument in the route decorator.
What will Flask do if two functions have the same route?
✗ Incorrect
Flask overwrites the first function with the last one defined for the same route.
How do you capture a username from the URL in Flask?
✗ Incorrect
Angle brackets in the route capture parts of the URL as variables passed to the function.
What URL does
@app.route('/') represent?✗ Incorrect
The '/' route is the root URL, usually the home page of the website.
Explain how the
@app.route decorator works in Flask and how it connects URLs to functions.Think about how you tell Flask what to do when someone visits a web page.
You got /4 concepts.
Describe how to create a dynamic route in Flask that accepts a username from the URL.
Imagine you want to greet different users by name in the URL.
You got /4 concepts.