Challenge - 5 Problems
URL Builder Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate1:30remaining
What URL does url_for generate for a simple route?
Given this Flask route, what URL will
url_for('hello') produce?from flask import Flask, url_for
app = Flask(__name__)
@app.route('/hello')
def hello():
return 'Hello!'Attempts:
2 left
💡 Hint
Think about the exact route path defined in the decorator.
✗ Incorrect
The route is defined as '/hello', so url_for('hello') returns '/hello'. Flask does not add a trailing slash unless specified.
❓ state_output
intermediate1:30remaining
What URL is generated with dynamic route parameters?
Consider this Flask route with a dynamic segment:
What does
@app.route('/user/')
def profile(username):
return f"User: {username}" What does
url_for('profile', username='alice') return?Attempts:
2 left
💡 Hint
url_for replaces dynamic parts with the values you pass.
✗ Incorrect
The dynamic part is replaced by 'alice', so the URL is '/user/alice'.
📝 Syntax
advanced2:00remaining
Which url_for call raises a BuildError?
Given this route:
Which
@app.route('/post/')
def show_post(id):
return f"Post {id}" Which
url_for call will cause an error?Attempts:
2 left
💡 Hint
Check if all required parameters are provided.
✗ Incorrect
The route requires an 'id' parameter. Omitting it causes a BuildError.
🧠 Conceptual
advanced2:00remaining
What does url_for generate with _external=True?
Given this route:
What does
@app.route('/about')
def about():
return 'About page'What does
url_for('about', _external=True) return if the app runs on http://localhost:5000?Attempts:
2 left
💡 Hint
The _external flag adds the full URL including scheme and host.
✗ Incorrect
With _external=True, url_for returns the full URL including scheme and host.
🔧 Debug
expert2:30remaining
Why does this url_for call produce a TypeError?
Examine this code snippet:
Why does the
@app.route('/item/')
def item_detail(item_id):
return f"Item {item_id}"
url = url_for('item_detail', item_id='abc') Why does the
url_for call raise a TypeError?Attempts:
2 left
💡 Hint
Check the type expected by the route converter and the type passed.
✗ Incorrect
The route expects an integer for . Passing 'abc' (a string) causes a TypeError during URL building.