When user click to like a post the web page should not refresh(redirect)
and count of the likes should be updated.
 How can I achieve this please help me.

Here is my block of code
```
<a style="{% if request.session.email %}pointer-events: auto;{% else
%}pointer-events: none;{% endif %}"
                                  href="/post_comment_like/{{j.id}}">
                                   <i class="fa fa-thumbs-o-up"
aria-hidden="true"
                                      style="color: gray;"></i></a>
```
views.py
```
def post_comment_like(request, id):
    if (request.session.get('email') is None) or
(request.session.get('email') == ""):
        return HttpResponseRedirect("/home")

    email = request.session.get('email')
    qury = Comment.objects.get(id=id)
    obj_id = qury.object_id
    qury_like = Comment_like.objects.filter(email=email)
    qury_like = Comment_like.objects.filter(email=email, object_id=qury.id,
dislike_comment="1").first()
    if qury_like:
        qury_like.delete()
    save_form = Comment_like(email=email,
user_name=request.session.get('name'),
                                content_type=qury.content_type,
                                object_id=qury.id,
                                content=qury.content,
                                flag_reply=qury.flag_reply,
                                flag_comment_id=qury.flag_comment_id,
                                flag_level=qury.flag_level,
                                like_comment='1')
    save_form.save()
    qury.like_comment = '1'
    qury.dislike_comment = '0'
    qury.save()
    # return redirect(request.META.get('HTTP_REFERER'))
    return HttpResponseRedirect(reverse('detail', args=[str(obj_id)]))
```

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAMSz6bnXp1Mh8h%2BXvmQ7aW-uyB9dxqHwSmMMd8LB34vw515BkQ%40mail.gmail.com.

Reply via email to