Django-Secretballot 不起作用?
我正在使用 Django-secretballot 应用程序,它允许匿名投票。首先,我们注册一个用于秘密投票的模型,然后有一个函数 add_vote() ,它接受 2 个参数。 “令牌”和投票值(+1 或 -1)。
来自文档:
add_vote:
函数需要一个令牌和一个投票(+1或-1)并添加或更新该令牌的投票(可以通过将add_vote_name参数传递给enable_voting_on来重命名)
我应该传递什么‘令牌’? 我在views.py中使用了它
t=request.META['REMOTE_ADDR']
feed.add_vote(t,+1)
,但它不起作用。我的意思是,如果我尝试从不同的机器投票,则只会计算第一票。但当其他人投票支持相同的提要时,它不会增加。
任何使用过此应用程序或通过检查 找出我做错了什么的人文档。请帮忙。
I am using Django-secretballot app which allows anonymous voting. First we register a model for secret voting and then there is a function add_vote() which takes 2 arguments. 'Token' and vote value(+1 or -1).
from docs:
add_vote:
function that takes a token and a vote (+1 or -1) and adds or updates the vote for said token (can be renamed by passing add_vote_name parameter to enable_voting_on)
What am I supposed to pass in as 'Token'?
I used this in my views.py
t=request.META['REMOTE_ADDR']
feed.add_vote(t,+1)
Yet it does not work. I mean if I try voting from different machines, only first vote gets counted. But it does not get incremented when other vote for that same feed.
Anyone who has used this app or figured out what I am doing wrong by checking the doc. Please help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我是作者,虽然我最近没有积极开发它,但我希望你发现它有用。
令牌可以是您需要的任何唯一字符串,一般来说您拥有的应该可以工作,但有可能您位于代理后面,或者您的服务器配置中的 REMOTE_ADDR 存在另一个问题(这超出了我能够提供帮助的范围)
检查 REMOTE_ADDR 的值是否确实发生变化,还可以考虑使用 REMOTE_ADDR 和其他内容(例如用户代理或存储在 cookie 中的唯一值)的组合。
I'm the author and although I haven't actively developed it recently I hope you find it useful.
token can be any unique string you require, generally speaking what you have should work but there's a chance you're behind a proxy or there's another issue with REMOTE_ADDR in your server config (which is beyond what I'd be able to assist with)
Check that the value of REMOTE_ADDR is actually changing, also consider using a combination of REMOTE_ADDR and something else like a User Agent or unique value stored in a cookie.