Javascript 在django使用keith wood倒数计时器进行实时倒数
大家好,我正在使用keith wood倒计时,如何在用户登录后将默认倒计时设置为(14天)倒计时,即使用户注销或离开页面,倒计时仍然是多余的Javascript 在django使用keith wood倒数计时器进行实时倒数,javascript,jquery,html,django,jquery-countdown,Javascript,Jquery,Html,Django,Jquery Countdown,大家好,我正在使用keith wood倒计时,如何在用户登录后将默认倒计时设置为(14天)倒计时,即使用户注销或离开页面,倒计时仍然是多余的 <div id="defaultCountdown"></div> <script> $(function () { var austDay = new Date(); austDay = new Date(austDay.getFullYear() + 1, 1 - 1, 26); $('#de
<div id="defaultCountdown"></div>
<script>
$(function () {
var austDay = new Date();
austDay = new Date(austDay.getFullYear() + 1, 1 - 1, 26);
$('#defaultCountdown').countdown({until: austDay});
$('#year').text(austDay.getFullYear());
});
</script>
伙计们,请帮帮我,所以你想让每个用户的14天倒计时从用户登录之日算起?是的,Rory McCrossana先生仍然会继续,即使用户离开页面或登录,只需在
用户
模型中保存用户登录的日期时间(或到期时间,即登录时间+14天)。然后,您可以始终计算距离倒计时结束还有多少时间,并将其显示或作为可在javascript中使用的模板中的变量传递。请注意,您的登录方法(将request.POST['password']
与m.password
进行比较)是非常错误的。这意味着您在数据库中将密码保存为纯文本!永远不要那样做。
def profile(request):
if request.method != 'POST':
raise Http404('Only POSTs are allowed')
try:
m = User.objects.get(username=request.POST['username'])
if m.password == request.POST['password']:
aa = request.POST['username']
request.session['member_id'] = m.id
print(m.id)
return render(request, 'profile.html')
except User.DoesNotExist:
messages.Warning(request, 'Incorrect Username or Password.')
return render (request, "login.html")