Django:用户只能访问某些子域

Django: User only access to certain subdomain

我通过 django-subdomains 和 django 站点框架设置了子域,但我遇到了问题,那就是我不知道如何 link 用户只能访问某个子域.例如 company1 的 user1 只能访问 company1.arandomdomain.com

在这里找到答案How to get unique users across multiple Django sites powered by the "sites" framework?

简而言之,您必须编写自己的身份验证后端来检查您需要检查的条件。请在此处查看文档 https://docs.djangoproject.com/en/1.7/topics/auth/customizing/#writing-an-authentication-backend

在我的例子中,我必须首先检查用户是否是管理员,这样 he/she 才能继续,否则我必须检查链接到站点的用户配置文件并将其与当前站点匹配。