简体   繁体   English

如何为匿名用户创建类似 Django 的按钮?

[英]How to create Django like button for anonymous users?

I am using Django and my website has no user profiles so all are anonymous.我正在使用 Django,我的网站没有用户个人资料,所以都是匿名的。 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 .如果您没有任何方法来识别您的用户,那么最好的办法是将此信息存储在浏览器 cookieHTML5 本地存储中 (I don't advise using flash cookies since there is a long debate about them and they are harder to implement) (我不建议使用 flash cookie,因为关于它们的争论很长,而且它们更难实现)

You can't 100% restrict multiple votes, but you can make it very difficult for a regular user, by using:不能100% 限制多次投票,但是您可以通过使用以下方法使普通用户变得非常困难:

  • a cookie一块饼干
  • a DB entry with the voter's IP带有选民 IP 的数据库条目

Facebook seems to track uniqueness of likes when its tied to a facebook app though the XFBML script.当 Facebook 通过 XFBML 脚本与 Facebook 应用程序绑定时,它似乎会跟踪喜欢的独特性。 Regardless of whether I'm logged in or logged out of facebook, the like button seems to recognize that I've already voted.无论我是登录还是退出 Facebook,点赞按钮似乎都能识别出我已经投票。

While still in its infancy, there is a project called django-like-button which provides a wrapper for facebooks XFBML like button.虽然仍处于起步阶段,但有一个名为django-like-button的项目,它为 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.如果您使用 pip 和 virtualenv,您可以pip install django-like-button并按照 readme.rst 安装说明进行操作。 The project can be found on github.该项目可以在github上找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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