django报错解决 Forbidden (403) CSRF verification failed. Request aborted.

报错内容

Forbidden (403)
CSRF verification failed. Request aborted.

Help
Reason given for failure:

    Origin checking failed - https://active-mantis-distinct.ngrok-free.app does not match any trusted origins.
    
In general, this can occur when there is a genuine Cross Site Request Forgery, or when Django’s CSRF mechanism has not been used correctly. For POST forms, you need to ensure:

解决办法

setting.py 文件加入以下内容

www.***.com
为你当前访问域名

CSRF_TRUSTED_ORIGINS = ['https://**.com',]

搞定

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐