0
0
Flaskframework~10 mins

Route decorator (@app.route) in Flask - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a route for the home page using Flask.

Flask
from flask import Flask
app = Flask(__name__)

@app.[1]('/')
def home():
    return "Welcome to the home page!"
Drag options to blanks, or click blank then click option'
Astart
Brun
Curl
Droute
Attempts:
3 left
💡 Hint
Common Mistakes
Using @app.run instead of @app.route
Forgetting the parentheses after the decorator method
Using @app.url which is not a Flask decorator
2fill in blank
medium

Complete the code to create a route that responds to '/about' URL.

Flask
@app.[1]('/about')
def about():
    return "About us page"
Drag options to blanks, or click blank then click option'
Aroute
Bstart
Crun
Durl
Attempts:
3 left
💡 Hint
Common Mistakes
Using @app.run instead of @app.route
Missing the URL string inside the parentheses
Using @app.start which is not a Flask decorator
3fill in blank
hard

Fix the error in the route decorator to make the '/contact' page work.

Flask
@app.route[1]
def contact():
    return "Contact page"
Drag options to blanks, or click blank then click option'
A('/contact'
B('/contact')
C('/contact']
D['/contact']
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets instead of parentheses
Missing opening or closing parentheses
Mismatched quotes or brackets
4fill in blank
hard

Fill both blanks to create a route for '/user/<username>' that returns a greeting.

Flask
@app.[1]('/user/<[2]>')
def greet_user(username):
    return f"Hello, {username}!"
Drag options to blanks, or click blank then click option'
Aroute
Brun
Cusername
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Using @app.run instead of @app.route
Mismatching the variable name inside the URL and the function parameter
Using incorrect variable names inside the URL
5fill in blank
hard

Fill all three blanks to create a route for '/post/' that returns the post ID.

Flask
@app.[1]('/post/<[2]:[3]>')
def show_post(post_id):
    return f"Post number {post_id}"
Drag options to blanks, or click blank then click option'
Aroute
Bint
Cpost_id
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Using @app.run instead of @app.route
Forgetting the type converter before the variable name
Mismatching the variable name in the URL and function parameter