0
0
Flaskframework~20 mins

Why routing is Flask's core - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Flask Routing Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What does this Flask route return?
Given the Flask app code below, what will the browser display when visiting '/'?
Flask
from flask import Flask
app = Flask(__name__)

@app.route('/')
def home():
    return 'Welcome to Flask!'

if __name__ == '__main__':
    app.run()
AA blank page
B404 Not Found error
CWelcome to Flask!
D500 Internal Server Error
Attempts:
2 left
💡 Hint
Look at the function decorated with @app.route('/') and what it returns.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in this Flask route
Which option shows the correct way to define a route in Flask without syntax errors?
Flask
from flask import Flask
app = Flask(__name__)

@app.route('/hello')
def hello():
    return 'Hello!'

if __name__ == '__main__':
    app.run()
A@app.route('/hello')\ndef hello():\n return 'Hello!'
B@app.route('/hello')\ndef hello():\nreturn 'Hello!'
C@app.route('/hello')\ndef hello()\n return 'Hello!'
D@app.route('/hello')\nhello():\n return 'Hello!'
Attempts:
2 left
💡 Hint
Check indentation and colons after function definitions.
state_output
advanced
2:00remaining
What is the output when accessing a dynamic route?
Consider this Flask app code. What will be the output when visiting '/user/Alice' in the browser?
Flask
from flask import Flask
app = Flask(__name__)

@app.route('/user/<name>')
def user(name):
    return f'Hello, {name}!'

if __name__ == '__main__':
    app.run()
AHello, Alice!
BHello, <name>!
C404 Not Found error
D500 Internal Server Error
Attempts:
2 left
💡 Hint
Look at how the route uses and how the function uses that parameter.
🔧 Debug
advanced
2:00remaining
Why does this Flask route cause a 404 error?
Given the code below, why does visiting '/about' in the browser show a 404 error?
Flask
from flask import Flask
app = Flask(__name__)

@app.route('/about/', strict_slashes=True)
def about():
    return 'About page'

if __name__ == '__main__':
    app.run()
ABecause the function 'about' does not return a string
BBecause the route is defined with a trailing slash '/about/', but the URL visited is '/about' without the slash
CBecause Flask requires routes to be uppercase
DBecause the app.run() is missing debug=true
Attempts:
2 left
💡 Hint
Check the exact route string and the URL visited.
🧠 Conceptual
expert
3:00remaining
Why is routing considered the core of Flask?
Which option best explains why routing is the core concept in Flask?
ARouting handles database connections and queries automatically
BRouting styles the HTML pages with CSS and JavaScript
CRouting manages user authentication and sessions by default
DRouting connects URLs to Python functions, defining how the app responds to web requests
Attempts:
2 left
💡 Hint
Think about what happens when a user visits a web address in a Flask app.