【发布时间】:2020-08-20 04:05:13
【问题描述】:
我是 Django 的新手,我正在开发一个用户喜欢帖子的网站。我有一个关于如何在删除“喜欢”并仅显示点赞数之前设置点赞数长度的问题。当用户不点击“Like”按钮时,它会在“Like”按钮的侧面显示“LIKE”,但是当用户单击“Like”按钮时,它会在计数侧面显示“LIKE”而不是“LIKE”,因为我我正在使用 else 语句。我如何在喜欢计数的一侧显示“喜欢”。例如; '1 Liked' 然后,当 100 个用户点击 Like 按钮时,喜欢计数:'100'。但如果少于 100,点赞数将是 '99 Liked'
{% if post.liked_by_user %}
<button type="submit" name="post_id" value="{{ post.id }}" class="like float-left pl-2" >
<img src="{{ '/static/' }}images/heart_empty.png" width="24" height="24">
</button>
{% if post.likes.all %}
<a href="{% url 'site:likes_users' post.id %}" class="like-count font-small dark-grey-text font-weight-bold">
<span class="d-inline-block text-truncate" style="max-width:70px;position:relative;top:3px;">
{{ post.likes.count }}
</span>
</a>
{% else %}
<span class="like-count font-small dark-grey-text font-weight-bold">Like</span>
{% endif %}
{% endif %}
【问题讨论】: