settings.py
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
myview.py
@csrf_protect #ensure_csrf_cookie....etc i tried it.
def category(request):
context = RequestContext(request)
dic = {
'a': 'aaaa',
'b': 'bbb'
}
return render_to_response('cate.html', dic, context_instance=context)
cate.html
<form name="cateForm" id="cateForm" method="POST">
{% csrf_token %}
<input type="text" name="href" id="href" size="50">
</form>
我html查看源,然后csrf_token值为null。
答案 0 :(得分:2)
不要使用PE32 executable (CONSOLE)
,它已经过时了。请改用render_to_response
。
render
答案 1 :(得分:0)
render_to_response函数的context_instance参数,并在Django 1.10中删除了该参数。这里讨论了这个问题:Django error: render_to_response() got an unexpected keyword argument 'context_instance'。