我想在我的django项目中发布一个表单,导致“CSRF cookie not set.”错误。在
from django.shortcuts import render
from django.template import RequestContext
from pyBikeMilesApp.models import Eintrag
from django.template.context_processors import csrf
# Create your views here.
def index(request):
if request.method == 'POST':
print(request.POST)
# Get all posts from DB
eintraege = Eintrag.objects
return render(request,'index.html',{'Eintraege': eintraege})
在生成的页面中,我可以看到csrf输入字段:
<input type='hidden' name='csrfmiddlewaretoken' value='zzRnENjz6wrUP8Op8IVOIDsUVvclY37k' />
有什么办法,怎么解决?在
我刚才有个问题:Django - AJAX not working due to csrf token not working on windows
简而言之,将
@ensure_csrf_cookie
放在视图定义之前。在即
相关问题 更多 >
编程相关推荐