解决方法:
1、查看浏览器有没有禁用cookie,有的话开启。
2、检查settings.py文件的MIDDLEWARE_CLASSES中是否有
'django.middleware.csrf.CsrfViewMiddleware',没有则添加
3、 在 templete 中, 为每个 POST form 增加一个 {% csrf_token %} tag. 如下:
{% csrf_token %}
4、在 view 中, 使用 django.template.RequestContext 而不是 Context. render_to_response, 默认使用 Context. 需要改成 RequestContext. 导入 class: from django.template import RequestContext
给 render_to_response 增加一个参数: def your_view(request): ... return render_to_response('template.html', your_data, context_instance=RequestContext(request) )