标签:
这里有答案
http://www.qttc.net/201209211.html
总结就是
1.在模板中要提交的form中加入{% csrf_token %}
<form method="post"> {% csrf_token %} {{form.as_p}} <input type="submit" name="ok"> </form>
2.把views中的
render_to_response(‘h1.html‘,{‘form‘:form})
改成
render_to_response(‘h1.html‘,{‘form‘:form},context_instance=RequestContext(request))
from django.shortcuts import render_to_response, RequestContext from django.http import HttpResponse from appA.models import * from appA.forms import * def hello(request): if request.method ==‘POST‘: form = Mybook(request.POST) if form.is_valid(): data = form.cleaned_data name = data[‘name‘] return HttpResponse(name) form = Mybook() return render_to_response(‘h1.html‘,{‘form‘:form},context_instance=RequestContext(request))
Django 表单 POST CSRF verification failed. Request aborted.错误
标签:
原文地址:http://www.cnblogs.com/JamesZhangXX/p/4652099.html