0

In my home.html page, I am trying to include a header.html file along with extending base.html. Following is my code

{% extends "base.html" %}

{% block body %}
   {% include 'header.html' %}

   # including the block navigation from header.html
   <nav id='header-nav'>{% block nav %} {% endblock %}</nav>

   # including the block image from header.html
   <div id='header-img'>{% block image %} {% endblock %}</div>

   # Reusing the same navigation in footer from header.html
   <div id='footer-nav'>{% block nav %} {% endblock %}</div>

{% endblock %}

Home.html looks like the following

{% block image %}<h1>I am image</h1>{% endblock %}
{% block nav %}<h1>I am navigation</h1>{% endblock %}

However, it returns an error - ''block' tag with name 'nav' appears more than once'.

Why is that? Is there any solutions to this?

Regards

4

1 回答 1

0

您在同一个模板中包含了两次 {% block nav %}。这就是它抛出错误的原因。也许你打算做 {% block footer %}?

{% extends "base.html" %}

{% block body %}
   {% include 'header.html' %}

   # including the block navigation from header.html
   <nav id='header-nav'>{% block nav %} {% endblock %}</nav>

   # including the block image from header.html
   <div id='header-img'>{% block image %} {% endblock %}</div>

   # Name this block something else i.e add a new block in header.html
   # and this error should clear up.
   <div id='footer-nav'>{% block footer %} {% endblock %}</div>

{% endblock %}
于 2018-11-19T05:46:20.597 回答