잠시 동안 문제가 발생했습니다. CSRF 쿠키가 설정되지 않았습니다. 아래 코드를보세요
파이썬
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에 코드가 있습니다.
HTML
<form action="/deposit/{{ account_num }}/" method="post">
<table>
<tr>
{{ account_form.bal_change }}
<input type="submit" value="Deposit" />
</tr>
{% csrf_token %}
</table>
</form>
Im 붙어서 이미 쿠키를 지우고 다른 브라우저를 사용했지만 여전히 csrf 쿠키가 설정되지 않았습니다.
CsrfViewMiddleware
당신의MIDDLEWARE_CLASSES
설정에 있습니까?