[Solved]-Django 'block' tag with name 'content' appears more than once


Yes, the error is quite clear: you have two blocks named “content”.

To be honest I can’t understand what you’re doing, as the second block seems to be an exact duplicate of the first. You can’t have two extends tags either.


You can do the things you want to in the back-end, ie:- Python.
You can for example do something like:-

# views.py::
if something is True(any condition for that matter)
msg = "something"

msg = "Something else"

# template, it is here -- index.html::
{% block title %}{{msg}}{% endblock title %}


If there is any variable that you want to render it more than once.
Just pass as input while rendering the file.
Like This:

from django.shortcuts import render

def products_list(request):
    return render(request, "products/list.html",
            "title":"Products List"

Inside the HTML File:


    <title>{{ title }} | My  Website</title>

    <h1>{{ title }}:</h1>

This will be rendered like this:


    <title>Products List | My  Website</title>

    <h1>Products List:</h1>


I think sometimes the error code maybe a little straight forward, "I think". Anyway I solved this problem by deleting the extra line tag(s), in this case the {% block content %} line tag.


In my case, it was solved by changing the name of the block content.

My scenario with this error was:
Some pages of my site are open to the public.
Some pages of my site are free for site users to see.

Because my user registration was entered in a user authentication step, I was checking the site. If it is anonymous, it must register first, so I had two options to check.
The first case (if anonymous) Ligen pages, home, rules and ..
Redomination mode (if the site user) pages, profiles and apps
I changed the content blocks to solve the name.
In the base.html file:
This base forum:

          {% block content1%}
          {% endblock content1%}

           block% block content2%}
          end% endblock content2%}

Leave a comment