看網(wǎng)上解決方法都是在方法上添加@csrf_exempt
不進行csrf
驗證歌懒,感覺治標(biāo)不治本。經(jīng)過學(xué)習(xí)django發(fā)送ajax鸣哀,得到解決方法坦刀,在ajax的data中加入csrfmiddlewaretoken:'{{ csrf_token }}'
例如:
$.post('{% url "blog:user_detail" user.id %}',
{
id: $(this).data('id'),
action: $(this).data('action'),
csrfmiddlewaretoken:'{{ csrf_token }}'
},
image.png
就會生成一個csrf字符串用于post驗證,問題解決臭杰。