Forbidden (403) CSRF verification failed. Request aborted.

Source: Internet
Author: User

Forbidden (403)
CSRF verification failed. Request aborted.
You is seeing this message because this site requires a CSRF cookie when submitting forms. This cookie was required for security reasons, to ensure that your browser was not being hijacked by third parties.
If you had configured your browser to disable cookies, please re-enable them, at least for this site, or for ' Same-origin ' Requests.
Help
Reason given for failure:
CSRF Cookie not set.

In general, this can occur when there are a genuine cross Site Request forgery, or when Django ' s CSRF mechanism have not bee n used correctly. For POST forms, you need to ensure:
Your Browser is accepting cookies.
The view function passes a request to the template ' s Render method.
In the template, there are a {% Csrf_token%} template tag inside each POST form that targets an internal URL.
If you is not using the Csrfviewmiddleware and then you must use Csrf_protect on any of the Csrf_token template tag, As well as those that accept the POST data.
You ' re seeing the "Help" section of the "This" page because you has DEBUG = True in your Django settings file. Change so to False, and only the initial error message would be displayed.
You can customize this page using the Csrf_failure_view setting.


been tossing for a long time, the final solution is to refer to the http://blog.csdn.net/middlekingt/article/details/8593031 inside add a decorator good.

But the problem remained, and later saw another way on this site: o Manually exclude a view function fromBeing handled by either of the and the Csrfmiddleware, you can use the Csrf_exempt decorator, foundinchTHEDJANGO.VIEWS.DECORATORS.CSRF module. For example: fromdjango.views.decorators.csrf Import csrf_exempt@csrf_exemptdef my_view (Request):returnHttpResponse ('Hello World'Like the middleware, the csrf_exempt decorator isComposed of parts:acsrf_view_exempt decorator and a csrf_response_exempt decorator, FoundIn the same module. These disable the View protection mechanism (csrfviewmiddleware) and the response post-processing (csrfresponsemiddleware) respectively. They can used individually ifrequired finally solved the problem. I actually bypassed the problem because Django introduced CSRF to avoid the cross Site Request forgeries attack, and the above workaround just forbids the Django feature. So in the future we have to study carefully, in the premise of this function can not help to submit a successful form. 

Forbidden (403) CSRF verification failed. Request aborted.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.