POST method always return 403 Forbidden

前端 未结 7 1661
走了就别回头了
走了就别回头了 2021-02-19 01:46

I have read Django - CSRF verification failed and several questions (and answers) related to django and POST method. One of the best-but-not-working-for-me answer is https://sta

7条回答
  •  孤独总比滥情好
    2021-02-19 01:57

    You also can use

    direct_to_template(request, 'library/search.html', result) 
    

    instead of

    render_to_response('library/search.html', result, context_instance=RequestContext(request))
    

    because direct_to_template adds RequestContext automatically. But note that direct_to_template is going to be deprecated and django offers to use CBV TemplateView instead.

    RequestContext allows you to use context processors. And this is your mistake: {% csrf_token %} outputed empty string and you got 403.

提交回复
热议问题