Recall & Review
beginner
What is the purpose of using
include in Flask templates?It allows you to reuse parts of HTML code (fragments) across multiple pages, making your templates cleaner and easier to maintain.
Click to reveal answer
beginner
How do you include a reusable fragment in a Flask template?
Use the Jinja2 syntax:
{% include 'filename.html' %} where filename.html is the fragment you want to reuse.Click to reveal answer
intermediate
Can included fragments in Flask templates access variables from the parent template?
Yes, included fragments share the same context and can use variables passed to the parent template.
Click to reveal answer
beginner
What is a practical example of using
include in Flask templates?You can create a header or footer HTML file and include it in all your pages to keep a consistent look and avoid repeating code.
Click to reveal answer
intermediate
What happens if the included file does not exist in Flask templates?
Flask will raise a template error when rendering, indicating the included file was not found.
Click to reveal answer
Which Jinja2 syntax is used to include a reusable fragment in a Flask template?
✗ Incorrect
The correct syntax to include a fragment is {% include 'fragment.html' %}.
What is a main benefit of using include for reusable fragments in Flask templates?
✗ Incorrect
Including reusable fragments helps avoid repeating code and keeps templates organized.
Can included fragments access variables defined in the parent template?
✗ Incorrect
Included fragments share the same context and can use variables from the parent template.
What happens if you include a non-existing file in a Flask template?
✗ Incorrect
Flask will raise an error indicating the included file was not found.
Which of these is a good use case for include in Flask templates?
✗ Incorrect
Including a navigation bar fragment helps reuse it on many pages easily.
Explain how and why you would use
include in Flask templates to reuse HTML fragments.Think about how websites have the same header on many pages.
You got /4 concepts.
Describe what happens if you try to include a file that does not exist in a Flask template.
Consider what happens if you try to open a missing file on your computer.
You got /3 concepts.