作者vanchy (vanchy)
看板Python
標題[問題] django的csrf_token
時間Thu Oct 13 20:58:12 2016
各位好,我正照著書上的步驟學習django
想做一個表單,採用POST方法,但一直卡在403 forbidden
我有照著document給的建議了,加了{% csrf_token %}和RequestContext
結果還是一樣403 forbidden
想請教各位該怎麼改才好?
謝謝^^
下面是template code
http://imgur.com/a/dHj12
而這個是我的view code
http://imgur.com/a/h7PI9
這是setting的middleware,裡面有設middleware.csrf.CsrfViewMiddleware了
http://imgur.com/a/E4OYj
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.44.75.197
※ 文章網址: https://webptt.com/m.aspx?n=bbs/Python/M.1476363495.A.2B9.html
1F:→ kevinkung: Settings有加嗎? 10/13 21:38
2F:推 gbllggi: MIDDLEWARE_CLASSES??? 10/13 22:43
3F:→ kevinkung: 'django.middleware.csrf.CsrfViewMiddleware' 10/14 10:32
4F:推 kevinkung: 你的'content'寫在哪裡?在template裡面沒看到!! 10/14 14:18
感謝糾正!不過我改成content之後,一樣403 forbidden....
※ 編輯: vanchy (114.44.76.32), 10/14/2016 20:28:04
5F:推 zaetheo: render_to_response()的指令好像在1.10版後使用就會有這 11/02 01:43
6F:→ zaetheo: 個問題,可以改成用response()指令,我也在這個問題卡好 11/02 01:43
7F:→ zaetheo: 久 11/02 01:43
8F:→ zaetheo: 更正,是render() 11/02 01:47
10F:→ zaetheo: ortcuts/ 11/02 01:48