转自:http://blog.csdn.net/chen_jint/article/details/12956797
解决步骤:
1〉django工程settings.py
-
MIDDLEWARE_CLASSES = (
-
'django.middleware.common.CommonMiddleware',
-
'django.contrib.sessions.middleware.SessionMiddleware',
-
'django.middleware.csrf.CsrfViewMiddleware',
-
'django.contrib.auth.middleware.AuthenticationMiddleware',
-
'django.contrib.messages.middleware.MessageMiddleware',
-
-
-
)
2〉html中的form添加模板标签{% csrf_token %}
-
<form action="." method="post">{% csrf_token %}
3〉django工程views.py
-
from django.shortcuts import render_to_response
-
from django.template import RequestContext
-
-
def some_view(request):
-
-
return render_to_response('my_template.html',
-
my_data_dictionary,
-
context_instance=RequestContext(request))
有疑问请戳Cross Site Request Forgery protection
P.S如果要屏蔽CSRF
方法1:注释掉django工程settings.py中
方法2:django工程views.py添加屏蔽装饰器
-
from django.views.decorators.csrf import csrf_exempt
-
@csrf_exempt
-
def some_view(request):
-
-
阅读(4405) | 评论(0) | 转发(0) |