Is django broken? I keep getting this error while nothing is wrong "Invalid block tag : 'endif'. Did you forget to register or load this tag?"

40 views Asked by At

Hi everyone please i keep getting this error "Invalid block tag : 'endif'. Did you forget to register or load this tag?" from my code, i have gone over the code severally and still can't figure out what the problem is

<nav id="navbar" class="navbar">
      <ul>
        {% if request.path == '/' or 'home' in request.path or 'contact' in
        request.path or 'login' in request.path or 'signup' in request.path %}
        <li>
          <a class="nav-link scrollto active" href="{% url 'home' %}">Home</a>
        </li>
        <li>
          <a class="nav-link scrollto" href="{% url 'home' %}#about">About</a>
        </li>
        <li>
          <a class="nav-link scrollto" href="{% url 'home' %}#services">Services</a>
        </li>
        <li><a href="{% url 'home' %}#blog">Blog</a></li>
        <li>
          <a class="nav-link scrollto" href="{% url 'home' %}#contact"
            >Contact</a>
        </li>
        {% if not user.is_authenticated %}
        <li>
          <a class="getstarted scrollto" href="{% url 'account_signup' %}"
            >Get Started</a>
        </li>
        {% else %}
        <li></li>
        {% endif %} {% elif request.path == '/' and not
        request.user.is_authenticated or request.path == 'home' and not
        request.user.is_authenticated or request.path == 'contact' and not
        request.user.is_authenticated %}

        <li>
          <a class="nav-link scrollto active" href="{% url 'home' %}">Home</a>
        </li>
        <li>
          <a class="nav-link scrollto" href="{% url 'home' %}#about">About</a>
        </li>
        <li>
          <a class="nav-link scrollto" href="{% url 'home' %}#services"
            >Services</a>
        </li>
        <li><a href="{% url 'home' %}#blog">Blog</a></li>
        <li>
          <a class="nav-link scrollto" href="{% url 'home' %}#contact"
            >Contact</a>
        </li>
        <li>
          <a class="getstarted scrollto" href="{% url 'home' %}#about"
            >Get Started</a>
        </li>
        {% endif %}
      </ul>
      <i class="bi bi-list mobile-nav-toggle"></i>
    </nav>

I have tried removing the affected endif and rewritting it slowly to make sure i didn't make a mistake, I have also checked if the the if statement i am closing has any errors like an unnecessary whitespace between the { and % but couldn't find any

2

There are 2 answers

0
hans On BEST ANSWER

I realized it was my code formatter (prettier) that was messing up the code so all I had to do was change the formatter and I stopped getting the error

2
Dishan Sachin On

Here is the correct code:

<nav id="navbar" class="navbar">
  <ul>
    {% if request.path == '/' or 'home' in request.path or 'contact' in request.path or 'login' in request.path or 'signup' in request.path %}
    <li>
      <a class="nav-link scrollto active" href="{% url 'home' %}">Home</a>
    </li>
    <li>
      <a class="nav-link scrollto" href="{% url 'home' %}#about">About</a>
    </li>
    <li>
      <a class="nav-link scrollto" href="{% url 'home' %}#services">Services</a>
    </li>
    <li><a href="{% url 'home' %}#blog">Blog</a></li>
    <li>
      <a class="nav-link scrollto" href="{% url 'home' %}#contact">Contact</a>
    </li>
    {% if not user.is_authenticated %}
    <li>
      <a class="getstarted scrollto" href="{% url 'account_signup' %}">Get Started</a>
    </li>
    {% endif %}
    {% elif request.path == '/' and not request.user.is_authenticated or request.path == 'home' and not request.user.is_authenticated or request.path == 'contact' and not request.user.is_authenticated %}
    <li>
      <a class="nav-link scrollto active" href="{% url 'home' %}">Home</a>
    </li>
    <li>
      <a class="nav-link scrollto" href="{% url 'home' %}#about">About</a>
    </li>
    <li>
      <a class="nav-link scrollto" href="{% url 'home' %}#services">Services</a>
    </li>
    <li><a href="{% url 'home' %}#blog">Blog</a></li>
    <li>
      <a class="nav-link scrollto" href="{% url 'home' %}#contact">Contact</a>
    </li>
    <li>
      <a class="getstarted scrollto" href="{% url 'home' %}#about">Get Started</a>
    </li>
    {% endif %}
  </ul>
  <i class="bi bi-list mobile-nav-toggle"></i>
</nav>

There were some issues like anchor tags are not closed. and update some of the condition statements that don't do anything.