我正在使用django。当我按下“赞”按钮时,浏览器的后退或下一按钮不起作用。我该如何解决这个问题?
views.py
def like_post(request):
post = get_object_or_404(Post, id=request.POST.get('post_id'))
is_liked = False
if post.likes.filter(id=request.user.id).exists():
post.likes.remove(request.user)
is_liked = False
else:
post.likes.add(request.user)
is_liked = True
return HttpResponseRedirect(post.get_absolute_url())
detail.html
<form action="{% url 'like_post' %}" method="post">
{% csrf_token %}
{% if is_liked %}
<button type="submit" name="post_id" value="{{post.id}}" class="btn btn-danger">Beğenme</button>
{% else %}
<button type="submit" name="post_id" value="{{post.id}}" class="btn btn-primary">Beğen</button>
{% endif %}
</form>