从 Perl 转到 Django 时发生 CSRF 错误

发布于 2024-11-01 20:53:55 字数 127 浏览 6 评论 0原文

我有一个网站,用户可以从 Perl 前端登录,然后重定向到 django 网站。该站点位于同一域,可能是不同的子域,但仍然是同一域。不幸的是,我们遇到了“CSRF 令牌丢失或不正确”的问题。错误。我该如何解决这个问题?

谢谢

I have a site where users can log in from a perl front end and then are redirected to a django site. The site is on the same domain, maybe a different subdomain but the same domain nevertheless. Unfortunately, we're getting hit w/ "CSRF token missing or incorrect." errors. How can I fix this?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不忘初心 2024-11-08 20:53:55

您是否将 CSRF 令牌传回 django?

查看 CSRF 文档
http://docs.djangoproject.com/en/dev/ref/ contrib/csrf/#exceptions
那里有很多好信息。

例如,请注意子域:

子域
默认情况下,CSRF cookie 特定于它们设置的子域
为了。这意味着提供了一个表格
来自一个子域(例如
server1.example.com)将无法
将目标放在另一个子域上
(例如 server2.example.com)。这
可以通过设置取消限制
CSRF_COOKIE_DOMAIN 是某种东西
例如“.example.com”。

您还可以通过 @csrf_exempt 装饰器对任何引发该错误的视图(在上面的链接中)禁用 CSRF 保护。

Are you passing the CSRF token back to django?

Check out the CSRF docs
http://docs.djangoproject.com/en/dev/ref/contrib/csrf/#exceptions
There is lots of good info there.

For example, note about subdomains:

Subdomains
By default, CSRF cookies are specific to the subdomain they are set
for. This means that a form served
from one subdomain (e.g.
server1.example.com) will not be able
to have a target on another subdomain
(e.g. server2.example.com). This
restriction can be removed by setting
CSRF_COOKIE_DOMAIN to be something
like ".example.com".

You could also disable CSRF protection for whatever view is throwing that error (in link above) via the @csrf_exempt decorator.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文