浏览器的“后退”或“下一个”按钮不起作用?

时间:2019-11-30 20:05:38

标签: python django button browser

我正在使用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>

0 个答案:

没有答案