如何为匿名用户创建类似 Django 的按钮?
我正在使用 Django,我的网站没有用户配置文件,因此所有用户都是匿名的。我想实施一个“点赞”系统。如何限制用户只能点赞一次。谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当 Facebook 通过 XFBML 脚本与 Facebook 应用程序绑定时,它似乎可以跟踪点赞的唯一性。无论我登录还是退出 Facebook,“赞”按钮似乎都会识别出我已经投票了。
insights
,可以在这里找到:http://www .facebook.com/insights/虽然仍处于起步阶段,但有一个名为 django-like-button 的项目,它为 facebook 的 XFBML 类似按钮提供了一个包装器。如果您使用 pip 和 virtualenv,则可以
pip install django-like-button
并按照 readme.rst 安装说明进行操作。该项目可以在 github 上找到。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.
insights
, which can be found here: http://www.facebook.com/insights/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 canpip install django-like-button
and follow the readme.rst installation instructions. The project can be found on github.如果您没有任何方法来识别您的用户,那么最好的办法就是将此信息存储在浏览器 cookie 或 HTML5 本地存储中。 (我不建议使用 flash cookie,因为关于它们的争论很长,而且它们更难实现)
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)
您无法 100% 限制多次投票,但您可以通过使用以下方式使普通用户变得非常困难:
You can't 100% restrict multiple votes, but you can make it very difficult for a regular user, by using: