Django CSRF Framework having many failures

后端 未结 4 566
逝去的感伤
逝去的感伤 2021-02-04 18:48

I\'m getting many failures from the CSRF Django middleware on my site (the version from SVN trunk.) The only errors I get are: CSRF failure: reason=CSRF token missing or incorr

4条回答
  •  我在风中等你
    2021-02-04 19:25

    Make sure your view function for GET Request looks like this:

    def login_view():
    c = {}
    c.update(csrf(request))
    request.session.set_expiry(0)
    if request.method == 'GET':
      return render_to_response('newform.html',c)
    

    Then check the view source for your newform.html, it must have Hidden field.

    <`form action="" method="post" name="loginform"> <`div style='display:none'`><`input type='hidden' name='csrfmiddlewaretoken' value='6f4dee99ab2f5e7201e057cb63' />
    

    Here, action can refer the same page, action="".

提交回复
热议问题