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?"

huangapple go评论65阅读模式
英文:

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?"

问题

大家好,请帮我解决这个错误:“无效的块标签:'endif'。您是否忘记注册或加载此标签?”我已经反复检查了我的代码,仍然无法找出问题所在。

<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' %}">首页</a>
        </li>
        <li>
          <a class="nav-link scrollto" href="{% url 'home' %}#about">关于</a>
        </li>
        <li>
          <a class="nav-link scrollto" href="{% url 'home' %}#services">服务</a>
        </li>
        <li><a href="{% url 'home' %}#blog">博客</a></li>
        <li>
          <a class="nav-link scrollto" href="{% url 'home' %}#contact"
            >联系</a>
        </li>
        {% if not user.is_authenticated %}
        <li>
          <a class="getstarted scrollto" href="{% url 'account_signup' %}"
            >开始</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' %}">首页</a>
        </li>
        <li>
          <a class="nav-link scrollto" href="{% url 'home' %}#about">关于</a>
        </li>
        <li>
          <a class="nav-link scrollto" href="{% url 'home' %}#services"
            >服务</a>
        </li>
        <li><a href="{% url 'home' %}#blog">博客</a></li>
        <li>
          <a class="nav-link scrollto" href="{% url 'home' %}#contact"
            >联系</a>
        </li>
        <li>
          <a class="getstarted scrollto" href="{% url 'home' %}#about"
            >开始</a>
        </li>
        {% endif %}
      </ul>
      <i class="bi bi-list mobile-nav-toggle"></i>
    </nav>
英文:

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

答案1

得分: 0

这是正确的代码:

<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>
英文:

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.

答案2

得分: 0

我意识到是我的代码格式化工具(prettier)在搞乱代码,所以我只需要更改格式化工具,就不再出现错误了。

英文:

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

huangapple
  • 本文由 发表于 2023年7月12日 22:02:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76671445.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定