D. <html><body><nav>Menu</nav><h1>Welcome</h1></body></html>
Solution
Step 1: Understand how {% include %} works
The {% include 'nav.html' %} inserts the content of nav.html exactly where the tag is placed.
Step 2: Combine the templates
In base.html, the <nav>Menu</nav> from nav.html appears before the <h1>Welcome</h1> inside the body.
Final Answer:
<html><body><nav>Menu</nav><h1>Welcome</h1></body></html> -> Option D
Quick Check:
Include inserts nav.html content inline [OK]
Hint: Include inserts file content exactly where placed [OK]
Common Mistakes:
Ignoring the included file content
Expecting an error if file exists
Thinking include replaces whole template
4. What is the error in this template snippet?
{% include header.html %}
medium
A. Filename should be a variable, not a string
B. Missing quotes around the filename
C. Incorrect tag name, should be import
D. Include tag cannot be used inside templates
Solution
Step 1: Check syntax for include tag
The filename must be a string literal enclosed in quotes, like 'header.html'.
Step 2: Identify the error
Here, header.html is unquoted, causing a syntax error.
Final Answer:
Missing quotes around the filename -> Option B
Quick Check:
Filename must be quoted in include [OK]
Hint: Always put quotes around filenames in include [OK]
Common Mistakes:
Omitting quotes around filename
Using import instead of include
Thinking include is invalid in templates
5. You want to create a reusable footer for your Flask app. Which approach correctly uses {% include %} to add footer.html to multiple pages and ensures easy updates?
hard
A. Add {% include 'footer.html' %} in each page template where footer is needed
B. Copy footer HTML code into every page template manually
C. Use {% extend 'footer.html' %} in each page template
D. Write footer HTML inside the Flask route function
Solution
Step 1: Understand reusable fragments with include
Using {% include 'footer.html' %} inserts the footer code wherever needed, keeping code DRY.
Step 2: Compare other options
Copying code manually duplicates it, {% extend %} is for inheritance, and writing HTML in route mixes logic and presentation.
Final Answer:
Add {% include 'footer.html' %} in each page template where footer is needed -> Option A
Quick Check:
Include footer in templates for easy updates [OK]
Hint: Use include tag in templates to reuse footer [OK]
Common Mistakes:
Copy-pasting footer code instead of including
Using extend instead of include for fragments
Mixing HTML in Python route code
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.