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评论104阅读模式
英文:

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'。您是否忘记注册或加载此标签?”我已经反复检查了我的代码,仍然无法找出问题所在。

  1. <nav id="navbar" class="navbar">
  2. <ul>
  3. {% if request.path == '/' or 'home' in request.path or 'contact' in
  4. request.path or 'login' in request.path or 'signup' in request.path %}
  5. <li>
  6. <a class="nav-link scrollto active" href="{% url 'home' %}">首页</a>
  7. </li>
  8. <li>
  9. <a class="nav-link scrollto" href="{% url 'home' %}#about">关于</a>
  10. </li>
  11. <li>
  12. <a class="nav-link scrollto" href="{% url 'home' %}#services">服务</a>
  13. </li>
  14. <li><a href="{% url 'home' %}#blog">博客</a></li>
  15. <li>
  16. <a class="nav-link scrollto" href="{% url 'home' %}#contact"
  17. >联系</a>
  18. </li>
  19. {% if not user.is_authenticated %}
  20. <li>
  21. <a class="getstarted scrollto" href="{% url 'account_signup' %}"
  22. >开始</a>
  23. </li>
  24. {% else %}
  25. <li></li>
  26. {% endif %} {% elif request.path == '/' and not
  27. request.user.is_authenticated or request.path == 'home' and not
  28. request.user.is_authenticated or request.path == 'contact' and not
  29. request.user.is_authenticated %}
  30. <li>
  31. <a class="nav-link scrollto active" href="{% url 'home' %}">首页</a>
  32. </li>
  33. <li>
  34. <a class="nav-link scrollto" href="{% url 'home' %}#about">关于</a>
  35. </li>
  36. <li>
  37. <a class="nav-link scrollto" href="{% url 'home' %}#services"
  38. >服务</a>
  39. </li>
  40. <li><a href="{% url 'home' %}#blog">博客</a></li>
  41. <li>
  42. <a class="nav-link scrollto" href="{% url 'home' %}#contact"
  43. >联系</a>
  44. </li>
  45. <li>
  46. <a class="getstarted scrollto" href="{% url 'home' %}#about"
  47. >开始</a>
  48. </li>
  49. {% endif %}
  50. </ul>
  51. <i class="bi bi-list mobile-nav-toggle"></i>
  52. </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

  1. <nav id="navbar" class="navbar">
  2. <ul>
  3. {% if request.path == '/' or 'home' in request.path or 'contact' in
  4. request.path or 'login' in request.path or 'signup' in request.path %}
  5. <li>
  6. <a class="nav-link scrollto active" href="{% url 'home' %}">Home</a>
  7. </li>
  8. <li>
  9. <a class="nav-link scrollto" href="{% url 'home' %}#about">About</a>
  10. </li>
  11. <li>
  12. <a class="nav-link scrollto" href="{% url 'home' %}#services">Services</a>
  13. </li>
  14. <li><a href="{% url 'home' %}#blog">Blog</a></li>
  15. <li>
  16. <a class="nav-link scrollto" href="{% url 'home' %}#contact"
  17. >Contact</a>
  18. </li>
  19. {% if not user.is_authenticated %}
  20. <li>
  21. <a class="getstarted scrollto" href="{% url 'account_signup' %}"
  22. >Get Started</a>
  23. </li>
  24. {% else %}
  25. <li></li>
  26. {% endif %} {% elif request.path == '/' and not
  27. request.user.is_authenticated or request.path == 'home' and not
  28. request.user.is_authenticated or request.path == 'contact' and not
  29. request.user.is_authenticated %}
  30. <li>
  31. <a class="nav-link scrollto active" href="{% url 'home' %}">Home</a>
  32. </li>
  33. <li>
  34. <a class="nav-link scrollto" href="{% url 'home' %}#about">About</a>
  35. </li>
  36. <li>
  37. <a class="nav-link scrollto" href="{% url 'home' %}#services"
  38. >Services</a>
  39. </li>
  40. <li><a href="{% url 'home' %}#blog">Blog</a></li>
  41. <li>
  42. <a class="nav-link scrollto" href="{% url 'home' %}#contact"
  43. >Contact</a>
  44. </li>
  45. <li>
  46. <a class="getstarted scrollto" href="{% url 'home' %}#about"
  47. >Get Started</a>
  48. </li>
  49. {% endif %}
  50. </ul>
  51. <i class="bi bi-list mobile-nav-toggle"></i>
  52. </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

这是正确的代码:

  1. <nav id="navbar" class="navbar">
  2. <ul>
  3. {% if request.path == '/' or 'home' in request.path or 'contact' in request.path or 'login' in request.path or 'signup' in request.path %}
  4. <li>
  5. <a class="nav-link scrollto active" href="{% url 'home' %}">Home</a>
  6. </li>
  7. <li>
  8. <a class="nav-link scrollto" href="{% url 'home' %}#about">About</a>
  9. </li>
  10. <li>
  11. <a class="nav-link scrollto" href="{% url 'home' %}#services">Services</a>
  12. </li>
  13. <li><a href="{% url 'home' %}#blog">Blog</a></li>
  14. <li>
  15. <a class="nav-link scrollto" href="{% url 'home' %}#contact">Contact</a>
  16. </li>
  17. {% if not user.is_authenticated %}
  18. <li>
  19. <a class="getstarted scrollto" href="{% url 'account_signup' %}">Get Started</a>
  20. </li>
  21. {% endif %}
  22. {% 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 %}
  23. <li>
  24. <a class="nav-link scrollto active" href="{% url 'home' %}">Home</a>
  25. </li>
  26. <li>
  27. <a class="nav-link scrollto" href="{% url 'home' %}#about">About</a>
  28. </li>
  29. <li>
  30. <a class="nav-link scrollto" href="{% url 'home' %}#services">Services</a>
  31. </li>
  32. <li><a href="{% url 'home' %}#blog">Blog</a></li>
  33. <li>
  34. <a class="nav-link scrollto" href="{% url 'home' %}#contact">Contact</a>
  35. </li>
  36. <li>
  37. <a class="getstarted scrollto" href="{% url 'home' %}#about">Get Started</a>
  38. </li>
  39. {% endif %}
  40. </ul>
  41. <i class="bi bi-list mobile-nav-toggle"></i>
  42. </nav>
英文:

Here is the correct code:

  1. <nav id="navbar" class="navbar">
  2. <ul>
  3. {% if request.path == '/' or 'home' in request.path or 'contact' in request.path or 'login' in request.path or 'signup' in request.path %}
  4. <li>
  5. <a class="nav-link scrollto active" href="{% url 'home' %}">Home</a>
  6. </li>
  7. <li>
  8. <a class="nav-link scrollto" href="{% url 'home' %}#about">About</a>
  9. </li>
  10. <li>
  11. <a class="nav-link scrollto" href="{% url 'home' %}#services">Services</a>
  12. </li>
  13. <li><a href="{% url 'home' %}#blog">Blog</a></li>
  14. <li>
  15. <a class="nav-link scrollto" href="{% url 'home' %}#contact">Contact</a>
  16. </li>
  17. {% if not user.is_authenticated %}
  18. <li>
  19. <a class="getstarted scrollto" href="{% url 'account_signup' %}">Get Started</a>
  20. </li>
  21. {% endif %}
  22. {% 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 %}
  23. <li>
  24. <a class="nav-link scrollto active" href="{% url 'home' %}">Home</a>
  25. </li>
  26. <li>
  27. <a class="nav-link scrollto" href="{% url 'home' %}#about">About</a>
  28. </li>
  29. <li>
  30. <a class="nav-link scrollto" href="{% url 'home' %}#services">Services</a>
  31. </li>
  32. <li><a href="{% url 'home' %}#blog">Blog</a></li>
  33. <li>
  34. <a class="nav-link scrollto" href="{% url 'home' %}#contact">Contact</a>
  35. </li>
  36. <li>
  37. <a class="getstarted scrollto" href="{% url 'home' %}#about">Get Started</a>
  38. </li>
  39. {% endif %}
  40. </ul>
  41. <i class="bi bi-list mobile-nav-toggle"></i>
  42. </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:

确定