python - Django likes button app error - "commit_id" different, but why the value of my cookies ​​are the same? -


This is my default choice Button App Config Now, "Commission_ID" is different, but why is the cookie worth the same? I want users to click on the button only once per day, but the following configuration is not successful. I'm a new thank you.

  class comments (models.model): article = model.arangky (article, related_name = 'article_id') user = model. (Approved user, related_name = 'comment_user_id') message = models.TextField (verbose_name = _ (u'Comment ')) created = models.DateTimeField (auto_now_add = true) likes = ModelskIntegerField (default = 0) = ModelskBooleanField (default = false) class meta (object): db_table = 'articles_comments' verbose_name_plural = _ (u'Comments') def __unicode __ (self): return (self-rescue self.message def): Super (comments self) .save ((request, commit_id): hash_id = hashlib.sha1 (Try 'commit_id'). Hexdigest ():  

If 'Has_aidi request Cookie: Returns HTTPPRP Spoint redirect (request.META.get ( 'HTTP_REFERER', '/')): command = Kmentskobjektskjet (ID = Kmetiaid) commit.likes + = 1 commit.save () response = HttpResponseRedirect (request.META. get ( 'HTTP_REFERER', '/')) response.set_cookie (commit_id, value = hash_id, MAX_AGE = 86400) HttpResponseRedirect return Http404 increase return response except ObjectDoesNotExist (request.META.get ( 'HTTP_REFERER', '/') )

url.py:

  url (r '^ addLiketoCommit  

issues:

< P>

img src = "https: // i .stack.imgur.com/8vpxm.png "alt =" Enter image details here ">

Fixed:

  def add_like_to_article_commit (request, commit_id): created_data = comments. Objets .get (id = commit_id) .created hash_id = hashlib.sha1 (str (created_date)). Hexdagest (try): if str (request.COOKIES.get (commit_id)) in hash_id: # & lt; ------ str () Return HttpResponseRedirect (request.META.get ('HTTP_REFERER', '/')) and: committed = Comments.objects.get (id = commit_id) commit.likes + = 1 commit.save () response = HttpResponseRedirect (request.META .Get ( 'HTTP_REFERER', '/')) response.set_signed_cookie (ObjectDoesNotExist except commit_id, value = hash_id, MAX_AGE = 86400) return response: increased Http404 return HttpResponseRedirect (request.META.get ('HTTP_REFERER', '/'))  

Enter image details here


Comments