【发布时间】:2021-12-09 07:01:39
【问题描述】:
帮助
失败原因:
Origin checking failed - https://praktikum6.jhoncena.repl.co does not match any trusted origins.
一般来说,当存在真正的跨站请求伪造时,或者没有正确使用 Django 的 CSRF 机制时,就会发生这种情况。对于 POST 表单,您需要确保:
Your browser is accepting cookies.
The view function passes a request to the template’s render method.
In the template, there is a {% csrf_token %} template tag inside each POST form that targets an internal URL.
If you are not using CsrfViewMiddleware, then you must use csrf_protect on any views that use the csrf_token template tag, as well as those that accept the POST data.
The form has a valid CSRF token. After logging in in another browser tab or hitting the back button after a login, you may need to reload the page with the form, because the token is rotated after a login.
您看到此页面的帮助部分是因为您的 Django 设置文件中有 DEBUG = True。将其更改为 False,将仅显示初始错误消息。
您可以使用 CSRF_FAILURE_VIEW 设置自定义此页面。
【问题讨论】:
-
我的回答是否解决了您的问题 Erico?
标签: python python-3.x django csrf django-csrf