[英]Users for multiple sites in Django
I am trying to get multiple sites to use the same database and code but in a way which forces each user to have their own login to each site. 我试图让多个站点使用相同的数据库和代码,但是以一种迫使每个用户对每个站点都有自己的登录名的方式。
I have seen a few suggestions as to how to make this work but I'm not sure which way to go. 我已经看到了一些有关如何进行这项工作的建议,但是我不确定该走哪条路。
I am using the Sites Framework, using the subdomain to identify the current site so I'm not using SITE_ID at all. 我正在使用Sites Framework,并使用子域来标识当前站点,因此我根本不使用SITE_ID。
Can anyone help with this? 有人能帮忙吗?
I quite like the idea of number 1 but I just need to get the request in the get_user() method so I can do this 我非常喜欢数字1的想法,但是我只需要在get_user()方法中获取请求,就可以做到这一点
def get_user(self, user_id):
try:
# I can't do this because there is no request available here
return User.objects.get(pk=user_id, site=request.site)
except User.DoesNotExist:
return None
to prevent people logged in to one site being able to log into another using the same session. 以防止登录到一个站点的人能够使用同一会话登录到另一个站点。
How I actually do it, not for users but for common databases, Is to design a main, hidden app with a REST API architecture. 实际上,我不是为用户而是为普通数据库这样做的,目的是设计一个具有REST API架构的主隐藏应用程序。 My other apps, naturally have their own DB and exchange their data via batch or stream process depending on the need. 我的其他应用程序自然有自己的数据库,并根据需要通过批处理或流处理过程交换数据。 I use django-rest-framework. 我使用django-rest-framework。
For your case what I would do is that whenever a user makes a Log In request I would send it via HTTPS to my main database and get it authenticated in my main app. 对于您的情况,我将要做的是,每当用户发出登录请求时,我都会通过HTTPS将其发送到主数据库,并在主应用程序中对其进行身份验证。 Whenever I would need to validate the user status I would simply make a get request to the main app. 每当我需要验证用户状态时,我只需向主应用程序发出获取请求即可。
This architecture is not that different from the one that many mobile apps have. 这种架构与许多移动应用程序所拥有的架构没有什么不同。
I hope it helps. 希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.