Challenge - 5 Problems
Template Inheritance Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the rendered output of this Flask template inheritance?
Given the base template
base.html and child template child.html, what will be the final rendered HTML when rendering child.html?Flask
{% raw %}
<!-- base.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<title>{% block title %}Base Title{% endblock %}</title>
</head>
<body>
<header>{% block header %}Base Header{% endblock %}</header>
<main>{% block content %}Base Content{% endblock %}</main>
<footer>{% block footer %}Base Footer{% endblock %}</footer>
</body>
</html>
<!-- child.html -->
{% extends "base.html" %}
{% block title %}Child Title{% endblock %}
{% block content %}
<p>Child Content</p>
{% endblock %}
{% endraw %}Attempts:
2 left
💡 Hint
Remember that blocks in the child template override blocks with the same name in the base template.
✗ Incorrect
The child template overrides the 'title' and 'content' blocks, so the final output uses 'Child Title' for the title and '
Child Content
' for the main content. The header and footer remain from the base template.📝 Syntax
intermediate1:30remaining
Which option correctly uses the extends tag in a Flask template?
Select the correct syntax to extend a base template named
layout.html in a Flask Jinja2 template.Attempts:
2 left
💡 Hint
The extends tag requires quotes around the template name and the correct keyword.
✗ Incorrect
The correct syntax uses the keyword 'extends' and quotes around the template name. Both single and double quotes are valid, but the keyword must be 'extends'.
🔧 Debug
advanced2:00remaining
Why does this Flask template raise a TemplateNotFound error?
Given this child template code, why does Flask raise a
TemplateNotFound error when rendering?Flask
{% raw %}{% extends 'base.htm' %}
{% block content %}
<p>Hello</p>
{% endblock %}{% endraw %}Attempts:
2 left
💡 Hint
Check the filename spelling carefully.
✗ Incorrect
Flask looks for the exact template filename. Since 'base.htm' does not exist but 'base.html' does, Flask raises TemplateNotFound.
❓ state_output
advanced2:30remaining
What is the output of this nested template inheritance?
Consider three templates:
base.html, middle.html extending base.html, and child.html extending middle.html. If base.html defines a block content with 'Base Content', middle.html overrides content with 'Middle Content', and child.html overrides content with 'Child Content', what will be rendered when rendering child.html?Flask
{% raw %}
<!-- base.html -->
<html><body>{% block content %}Base Content{% endblock %}</body></html>
<!-- middle.html -->
{% extends 'base.html' %}
{% block content %}Middle Content{% endblock %}
<!-- child.html -->
{% extends 'middle.html' %}
{% block content %}Child Content{% endblock %}
{% endraw %}Attempts:
2 left
💡 Hint
The most specific child template's block overrides all parent blocks with the same name.
✗ Incorrect
In nested inheritance, the last child template's block content replaces the same block in all parents. So 'Child Content' is rendered.
🧠 Conceptual
expert2:00remaining
What happens if a block is missing in the child template when using extends?
If a child template extends a base template that defines a block named
sidebar, but the child template does not override this block, what will be the output in the rendered page?Attempts:
2 left
💡 Hint
Blocks in base templates provide default content if not overridden.
✗ Incorrect
If a child template does not override a block, the base template's block content is used as default. No error occurs.