Django CSRF Cookie未设置 [英] Django CSRF Cookie Not Set
本文介绍了Django CSRF Cookie未设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我现在有一些问题,我遇到了CSRF Cookie未设置。请看下面的代码
I have some problem for a while now, I'm experiencing CSRF Cookie not set. Please look at the codes below
def deposit(request,account_num):
if request.method == 'POST':
account = get_object_or_404(account_info,acct_number=account_num)
form_=AccountForm(request.POST or None, instance=account)
form = BalanceForm(request.POST)
info = str(account_info.objects.filter(acct_number=account_num))
inf=info.split()
if form.is_valid():
#cd=form.cleaned_data
now = datetime.datetime.now()
cmodel = form.save()
cmodel.acct_number=account_num
#RepresentsInt(cmodel.acct_number)
cmodel.bal_change="%0.2f" % float(cmodel.bal_change)
cmodel.total_balance="%0.2f" %(float(inf[1]) + float(cmodel.bal_change))
account.balance="%0.2f" % float(cmodel.total_balance)
cmodel.total_balance="%0.2f" % float(cmodel.total_balance)
#cmodel.bal_change=cmodel.bal_change
cmodel.issued=now.strftime("%m/%d/%y %I:%M:%S %p")
account.recent_change=cmodel.issued
cmodel.save()
account.save()
return HttpResponseRedirect("/history/" + account_num + "/")
else:
return render_to_response('history.html',
{'account_form': form},
context_instance=RequestContext(request))
在这里HTML是代码
<form action="/deposit/{{ account_num }}/" method="post">
<table>
<tr>
{{ account_form.bal_change }}
<input type="submit" value="Deposit" />
</tr>
{% csrf_token %}
</table>
</form>
我卡住了,我已经清除了cookie,使用其他浏览器,但仍然没有设置csrf cookie。 p>
Im stuck, I already cleared the cookie, used other browser but still csrf cookie not set.
推荐答案
如果 CSRF_COOKIE_SECURE = True
已设置,并且您正在访问该网站不安全。
This can also occur if CSRF_COOKIE_SECURE = True
is set and you are accessing the site non-securely.
这篇关于Django CSRF Cookie未设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文