Django-异常值:if标签中的表达式意外结束

我无法弄清楚错误可能是什么。我检查了文档以查看是否有任何语法更改,但我没有找到任何更改。

Unexpected end of expression in if tag.

Template error:
In template /home/dhruv/django-blog/blog/templates/blog/post_detail.html, error at line 5
   Unexpected end of expression in if tag.
   1 : {% extends 'blog/base.html' %}
   2 : 
   3 : {% block content %}
   4 :     <div>
   5 :          {% if post.published_date %} 
   6 :             <div>
   7 :                 {{ post.published_date }}
   8 :             </div>
   9 :         {% elif %}
   10 :             <a href="{% url 'post_publish' pk=post.pk %}">
   11 :                 Publish!
   12 :             </a>
   13 :         {% endif %}
   14 : 
   15 :         {% if user.is_authenticated %}

回答

代替:

{% elif %}

{% else %}

************关于 if/else 的文档。

if/else 可以通过以下方式使用:

{% if condition %}
{% endif %}

或者

{% if condition1 %}
{% elif condition2 %} # in your case, you are missing condition2
{% endif %}

或者

{% if condition1 %}
{% elif condition2 %} 
{% else %}
{% endif %}

或者

{% if condition %}
{% else %}
{% endif %}


以上是Django-异常值:if标签中的表达式意外结束的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>