Challenge - 5 Problems
Flask Variable Substitution Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
📝 Syntax
intermediate1:30remaining
What is the output of this Flask template code?
Given the Flask template snippet below, what will be rendered when
name = 'Alice' is passed to the template?Flask
Hello, {{ name }}!Attempts:
2 left
💡 Hint
Remember that double curly braces {{ }} are used to insert variable values in Flask templates.
✗ Incorrect
In Flask templates, {{ name }} is replaced by the value of the variable 'name'. So if name is 'Alice', the output is 'Hello, Alice!'.
❓ component_behavior
intermediate1:30remaining
What happens if a variable is missing in Flask template substitution?
Consider this Flask template code:
If the variable
User: {{ username }}If the variable
username is not provided in the template context, what will be rendered?Attempts:
2 left
💡 Hint
Flask's template engine replaces missing variables with empty strings by default.
✗ Incorrect
If a variable is missing, Flask's Jinja2 template engine inserts an empty string instead of raising an error or showing the variable name.
🔧 Debug
advanced2:00remaining
Identify the error in this Flask template variable substitution
What error will occur when rendering this Flask template?
Hello, {{ user.name }!Attempts:
2 left
💡 Hint
Check the syntax of the variable substitution braces carefully.
✗ Incorrect
The template has a missing closing curly brace '}}' after 'user.name'. This causes a syntax error during template rendering.
❓ state_output
advanced1:30remaining
What is the output of this Flask template with filters?
Given the Flask template:
and the context
{{ message|upper }}and the context
{'message': 'hello world'}, what is the rendered output?Attempts:
2 left
💡 Hint
The filter 'upper' converts text to uppercase.
✗ Incorrect
The 'upper' filter changes all letters to uppercase, so 'hello world' becomes 'HELLO WORLD'.
🧠 Conceptual
expert2:30remaining
Which option correctly escapes HTML in Flask variable substitution?
In Flask templates, how does variable substitution handle HTML special characters by default?
Given
Given
text = 'bold', what will {{ text }} render as?Attempts:
2 left
💡 Hint
Flask templates escape HTML characters to prevent code injection by default.
✗ Incorrect
Flask's Jinja2 escapes HTML special characters like < and > to their safe equivalents < and > to avoid rendering raw HTML.