简体   繁体   中英

How to create Django like button for anonymous users?

I am using Django and my website has no user profiles so all are anonymous. I want to implement a 'like' system. How do I restrict a user to like only once. Thanks.

If you don't have any way of identifying your users then your best bet is to store this info in a browser cookie or HTML5 local storage . (I don't advise using flash cookies since there is a long debate about them and they are harder to implement)

You can't 100% restrict multiple votes, but you can make it very difficult for a regular user, by using:

  • a cookie
  • a DB entry with the voter's IP

Facebook seems to track uniqueness of likes when its tied to a facebook app though the XFBML script. Regardless of whether I'm logged in or logged out of facebook, the like button seems to recognize that I've already voted.

While still in its infancy, there is a project called django-like-button which provides a wrapper for facebooks XFBML like button. If you're using pip and virtualenv, you can pip install django-like-button and follow the readme.rst installation instructions. The project can be found on github.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM