0
0
Djangoframework~10 mins

Template inheritance with base template in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to extend the base template in Django.

Django
{% extends '[1]' %}

{% block content %}
<p>Welcome to the homepage!</p>
{% endblock %}
Drag options to blanks, or click blank then click option'
Aindex.html
Bbase.html
Chome.html
Dmain.html
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong filename in the extends tag.
Forgetting to put the filename in quotes.
2fill in blank
medium

Complete the code to define a block named 'content' in the base template.

Django
<body>
  {% block [1] %}
  <!-- Default content -->
  {% endblock %}
</body>
Drag options to blanks, or click blank then click option'
Acontent
Bheader
Cfooter
Dsidebar
Attempts:
3 left
💡 Hint
Common Mistakes
Using a block name that does not match the child template.
Forgetting to close the block with {% endblock %}.
3fill in blank
hard

Fix the error in the child template to correctly override the 'content' block.

Django
{% extends 'base.html' %}

{% block [1] %}
<h1>Hello, world!</h1>
{% endblock %}
Drag options to blanks, or click blank then click option'
Acontent
Bmain
Cfooter
Dheader
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different block name than the base template.
Forgetting to use the block tag in the child template.
4fill in blank
hard

Fill both blanks to create a base template with a block named 'title' and a block named 'content'.

Django
<html>
<head>
  <title>{% block [1] %}My Site{% endblock %}</title>
</head>
<body>
  {% block [2] %}
  <p>Welcome!</p>
  {% endblock %}
</body>
</html>
Drag options to blanks, or click blank then click option'
Atitle
Bheader
Ccontent
Dfooter
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up block names.
Not closing blocks properly.
5fill in blank
hard

Fill all three blanks to create a child template that extends 'base.html', overrides the 'title' block with 'Home Page', and overrides the 'content' block with a welcome message.

Django
{% extends '[1]' %}

{% block [2] %}Home Page{% endblock %}

{% block [3] %}
<p>Welcome to the home page!</p>
{% endblock %}
Drag options to blanks, or click blank then click option'
Abase.html
Btitle
Ccontent
Dhome.html
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong filename in extends.
Using incorrect block names.
Forgetting to close blocks.