It is a cross site problem and a Django prevention mechanism. The error reports are as follows:
Generally, this can happen when a genuine cross-site request is forged, or when Django’s CSRF mechanism is not being used correctly. For POST forms, you need to make sure that:
Your browser is accepting cookies.
The view function passes a request to the template’s rendering method.
In the template, each POST form has a {% csrf_token %} template token pointing to an internal URL.
If you are not using the CsrfViewMiddleware, then you must use csrf_protect on any view that uses the csrf_token template tag and on those views that accept POST data.
The form has a valid CSRF token. You may need to reload the page with the form after logging in to another browser tab or clicking the back button after logging in, as the token is rotated after logging in.
You will see the help section of this page because there is DEBUG = True in your Django settings file. changing it to False will only show the initial error message.
You can customize this page using the CSRF_FAILURE_VIEW setting.
As the error message suggests, there are two ways we can do this.
1. go to setting and comment out # ‘django.middleware.csrf.CsrfViewMiddleware’
This is the same as removing the middleware from the cross-site prevention mechanism. Then not this error is reported, but if we really encounter cross-domain problems, we may not know it is reported this error, not very recommended.
2. Add {% csrf_token %} to the form below
Read More:
- [Solved] Request.url is not modifiable, use Request.replace() instead
- How to Fix “HTTP error 403: forbidden” in Python 3. X
- [Solved] Python requests ConnectionError Error: connection aborted BadStatusLine
- urllib.error.HTTPError http error 403 forbidden
- urllib.error.HTTPError: HTTP Error 403: Forbidden [How to Solve]
- Python requests Error: ConnectionError: (‘Connection aborted.‘, error(104, ‘Connection reset by peer‘))
- To solve the problem that the loss of verification set of resnet50 pre-training model remains unchanged
- Gunicorn Flask Error: [ERROR] Socket error processing request
- When sending HTTP request, python encountered: error 54, ‘connection reset by peer’ solution
- How to Solve Error: Unverified HTTPS request is being made
- Jupyter notebook Failed to Switch to the Virual Environment: DLL load failed python.exe could not find the entry
- [Solved] Pytorch Error: PytorchStreamReader failed reading zip archive failed finding central directory
- [Solved] Pytorch Error: PytorchStreamReader failed reading zip archive failed finding central directory
- Failed to Create New Environment Error: Collecting package metadata (current_repodata.json): failed.
- [Solved] PyCharm Failed to Start Error: failed to create jvm.jvm path…
- Python Error: Failed to establish a new connection: [Errno -2] Name or service not known
- Failed to establish a new connection: [winerror 10048] in the requests thread pool, the interface is called circularly to get the datagram error
- [Solved] from django.core.cache import cache Error
- Importerror: DLL load failed: unable to find the specified module in Python