You need write Ajax for this functionality to implement On Wed, 5 May, 2021, 6:40 PM Derek, <gamesb...@gmail.com> wrote:
> You'll need to use javascript for this - have a look at > https://data-flair.training/blogs/ajax-in-django/ for an example. > > On Wednesday, 5 May 2021 at 05:30:59 UTC+2 sali...@rohteksolutions.com > wrote: > >> 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/f44ffafe-9d01-43ac-a7ce-43286551aec4n%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/f44ffafe-9d01-43ac-a7ce-43286551aec4n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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/CAAYXZx_T8fqHCFyEs48cWDWmp07%3D1EN4H%3DzxMrF487xGcZXiOQ%40mail.gmail.com.