Complete the code to define a Flask route that responds to '/home/' with a trailing slash.
from flask import Flask app = Flask(__name__) @app.route('/home[1]') def home(): return 'Welcome Home!'
The trailing slash '/' in the route decorator means the URL must end with a slash. Flask will redirect '/home' to '/home/' automatically.
Complete the code to define a Flask route that responds to '/about' without a trailing slash.
from flask import Flask app = Flask(__name__) @app.route('/about[1]') def about(): return 'About Page'
When the route does not have a trailing slash, Flask will not redirect URLs with a slash to this route. The URL must match exactly '/about'.
Fix the error in the route decorator to correctly handle the URL '/contact/' with a trailing slash.
from flask import Flask app = Flask(__name__) @app.route('/contact[1]') def contact(): return 'Contact Us'
The route should end with a single '/' to indicate a trailing slash. Using '/contact/' twice or no slash causes errors or unexpected behavior.
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.
from flask import Flask app = Flask(__name__) @app.route('/profile', strict_slashes=[1]) def profile(): return 'User Profile'
Setting the route without a trailing slash and strict_slashes=True means Flask will redirect '/profile/' to '/profile'.
Fill all three blanks to define a Flask route that accepts '/dashboard/' with a trailing slash and disables automatic redirect for missing slash URLs.
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/'
Using a trailing slash in the route and strict_slashes=False disables Flask's automatic redirect from '/dashboard' to '/dashboard/'.