0
0
Flaskframework~10 mins

Trailing slash behavior 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 define a Flask route that responds to '/home/' with a trailing slash.

Flask
from flask import Flask
app = Flask(__name__)

@app.route('/home[1]')
def home():
    return 'Welcome Home!'
Drag options to blanks, or click blank then click option'
A/
C//
Dhome/
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving out the slash causes Flask to redirect automatically, which might confuse beginners.
2fill in blank
medium

Complete the code to define a Flask route that responds to '/about' without a trailing slash.

Flask
from flask import Flask
app = Flask(__name__)

@app.route('/about[1]')
def about():
    return 'About Page'
Drag options to blanks, or click blank then click option'
A/
C//
Dabout/
Attempts:
3 left
💡 Hint
Common Mistakes
Adding a slash causes Flask to redirect '/about' to '/about/' which is not intended here.
3fill in blank
hard

Fix the error in the route decorator to correctly handle the URL '/contact/' with a trailing slash.

Flask
from flask import Flask
app = Flask(__name__)

@app.route('/contact[1]')
def contact():
    return 'Contact Us'
Drag options to blanks, or click blank then click option'
B/contact/
C/
D//
Attempts:
3 left
💡 Hint
Common Mistakes
Using double slashes or repeating the route name inside the decorator.
4fill in blank
hard

Complete the code to create a Flask route that accepts '/profile' without a slash and '/profile/' with a slash, redirecting the slash version to the no-slash version.

Flask
from flask import Flask
app = Flask(__name__)

@app.route('/profile', strict_slashes=[1])
def profile():
    return 'User Profile'
Drag options to blanks, or click blank then click option'
B/
CTrue
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Adding a slash in the route string or setting strict_slashes=False disables the redirect behavior.
5fill in blank
hard

Fill all three blanks to define a Flask route that accepts '/dashboard/' with a trailing slash and disables automatic redirect for missing slash URLs.

Flask
from flask import Flask
app = Flask(__name__)

@app.route('/dashboard[1]', strict_slashes=[2])
def dashboard():
    return 'Dashboard Page'

# Accessing '/dashboard' will [3] redirect to '/dashboard/'
Drag options to blanks, or click blank then click option'
A/
BTrue
Cnot trigger
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Setting strict_slashes=True causes Flask to redirect automatically.