Session problem of Django

blog"s article like function, like once + 1, use session to record the current user
problem point is: if you like article 1, article 2 will indicate that it has been supported. The reason is to judge that session
how to realize that articles cannot be liked repeatedly

View Code

class LikeNumView(View):
    def post(self, request):
        if request.session.get("has_like", False):
            return HttpResponse("{"status":"fail", "msg":""}", content_type="application/json")
        comments_id = request.POST.get("comments_id", "")
        blog = Blog.objects.get(id=int(comments_id))
        blog.like_number += 1
        blog.save()
        request.session["has_like"] = True
        return HttpResponse("{"status":"success", "msg":""}", content_type="application/json")

ajax Code
function like () {

            $.ajax({
                cache: false,
                type: "POST",
                url: "{% url "like" %}",
                data: {"comments_id":{{ comments.id }}},
                async: true,
                beforeSend:function(xhr, settings){
                    xhr.setRequestHeader("X-CSRFToken", "{{ csrf_token }}");
                },
                success:function (data) {
                    if (data.status=="fail"){
                        layer.msg("")
                    }
                    else {
                        layers.msg("")
                    }
                }
            })
        }
Feb.26,2021

you can choose
1 and make a like record table. The ID, like time of ID, article is
2, and the like record is stored in redis. The key value is the user ID+ article ID, value is the like time

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e724a7-3c7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e724a7-3c7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?