Challenge - 5 Problems
Render Template Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this Flask route render?
Given this Flask route, what will the user see when visiting
/hello?Flask
from flask import Flask, render_template app = Flask(__name__) @app.route('/hello') def hello(): return render_template('greet.html', name='Alice')
Attempts:
2 left
💡 Hint
Think about what render_template does with the variables passed to it.
✗ Incorrect
render_template loads the HTML file and replaces placeholders with the variables given, so the user sees the HTML with 'Alice' where 'name' is used.
📝 Syntax
intermediate2:00remaining
Identify the syntax error in this render_template usage
What is wrong with this Flask route code?
Flask
from flask import Flask, render_template app = Flask(__name__) @app.route('/user') def user(): return render_template('user.html', username=)
Attempts:
2 left
💡 Hint
Check how variables are passed to render_template.
✗ Incorrect
render_template expects keyword arguments like 'username=value'. Here, 'username' is passed without a value, causing a syntax error.
❓ state_output
advanced2:00remaining
What is the output of this Flask route with conditional rendering?
Consider this route and template. What will the user see when visiting
/status?Flask
from flask import Flask, render_template app = Flask(__name__) @app.route('/status') def status(): user_logged_in = False return render_template('status.html', logged_in=user_logged_in) # status.html content: # {% if logged_in %} # <p>Welcome back!</p> # {% else %} # <p>Please log in.</p> # {% endif %}
Attempts:
2 left
💡 Hint
Look at the value of 'user_logged_in' and the template's if condition.
✗ Incorrect
The variable 'logged_in' is False, so the else block runs, showing 'Please log in.'
🔧 Debug
advanced2:00remaining
Why does this Flask app raise a TemplateNotFound error?
This Flask route raises a TemplateNotFound error. What is the most likely cause?
Flask
from flask import Flask, render_template app = Flask(__name__) @app.route('/page') def page(): return render_template('mypage.html')
Attempts:
2 left
💡 Hint
Check where Flask looks for template files by default.
✗ Incorrect
Flask looks for templates in the 'templates' folder. If 'mypage.html' is missing there, TemplateNotFound error occurs.
🧠 Conceptual
expert3:00remaining
How does Flask's render_template handle variable scope?
When you pass variables to
render_template, how are they accessed inside the template?Attempts:
2 left
💡 Hint
Think about how templates use placeholders for variables.
✗ Incorrect
Flask injects the passed variables into the template context, so you can use them directly by name in the template.