英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论