Django_hosts无法使用Django的默认身份验证 [英] Django_hosts Not Working With Django's Default Authentication

查看:64
本文介绍了Django_hosts无法使用Django的默认身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用名为 django_hosts 的程序包来重新路由某些应用程序的URL.

I'm using this package called django_hosts to re-route urls for some apps.

除django_hosts不适用于Django Authentication之外,其他一切都正常.

Everything is working fine except for the fact that django_hosts is not working with Django Authentication.

我托管了此url api.example.com,因此在此页面上具有url api.example.com:8000/add_post的用户,我希望用户添加帖子,但在执行此操作之前必须先进行身份验证.因此,登录后,我仍然无法通过无聊的形式提交帖子.但是当我回到example.com时,它表明我已经登录,但是api.example.com告诉我否则.

I hosted this url api.example.com, so on this page with the url api.example.com:8000/add_post, I want users to add post but before doing that you must be authenticated. So after I logged in, I still can't submit post via the form talkless of posting. But when I go back to example.com, it shows that I'm logged in but api.example.com is telling me otherwise.

如何使django身份验证与此程序包兼容?

How do I make django authentication work with this package?

推荐答案

问题是身份验证令牌已挂接到域.使用Django的默认配置, api.example.com 无法访问 example.com 身份验证令牌.

The problem is that the authentication token is hooked to the domain. Using Django's default configuration, the api.example.com can't access the example.com auth token.

您可以通过在 settings.py 模块中设置 SESSION_COOKIE_DOMAIN 配置来更改此行为:

You can change this behaviour by setting the SESSION_COOKIE_DOMAIN configuration in your settings.py module:

SESSION_COOKIE_DOMAIN = 'example.com'

但不要太快!请仔细做,否则您可能会破坏您的应用程序:

在生产站点上更新此设置时请小心.如果你更新此设置以在具有以下功能的网站上启用跨域Cookie以前使用的标准域cookie,现有的用户cookie将是设置为旧域.这可能导致他们无法登录只要这些cookie持续存在.

Be cautious when updating this setting on a production site. If you update this setting to enable cross-domain cookies on a site that previously used standard domain cookies, existing user cookies will be set to the old domain. This may result in them being unable to log in as long as these cookies persist.

有关官方文档的详细信息

这篇关于Django_hosts无法使用Django的默认身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆