与django-tenants注册后重定向到租户域吗? [英] Redirect to tenant domain after signup with django-tenants?

查看:254
本文介绍了与django-tenants注册后重定向到租户域吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用django-tenants库,其中的每个租户都是一个单独的隔离的postgres模式. django租户模块完成了许多繁重的工作,我得到了以下代码,每次有人注册时都会创建一个新的租户.我关心的是schema_context函数的内部,该函数成功地在新创建的架构中创建了一个用户,但是我关心的是如何登录该用户并将其重定向到customname.my-domain.com,如下所示:

I'm using a django-tenants library where each tenant is a separate, isolated postgres schema. The django tenants module does a lot of the heavy lifting and I've got the following code that creates a new tenant each time someone registers. My concern is inside the schema_context function which (successfully) creates a user in the newly created schema, but my concern is how I can log that user in and redirect them to customname.my-domain.com as seen below:

class SignupView(View):
    def get(self, request):
        form = RegistrationForm()
        return render(request, "accounts/signup.html", {"form": form})

    def post(self, request, *args, **kwargs):
        form = RegistrationForm(request.POST)
        if form.is_valid():
            instance = form.save(commit=False)
            tenant = Client(domain_url=company + ".my-domain.com", schema_name=company, name=company, paid_until="2019-05-10", on_trial=False)
            tenant.save()

            with schema_context(tenant.schema_name):
                instance.save()
                # login(request, instance) - how do I login this user 
                # render.... and redirect them to the newly created domain e.g company.my-domain.com
        return render(request, "accounts/signup.html", {"form": form})

推荐答案

我是Django Tenant的维护者.由于租户可能需要一些时间来设置,因此建议您使用芹菜来创建租户.设置租户后,我会向用户发送电子邮件以验证其帐户/租户,并将其带给租户.

I am the maintainer of Django Tenant. As the tenants can take some time to setup I suggest you use celery to create the tenant. Once the tenant is setup I would send the user an email to verify their account / tenant which take them to their tenant.

这篇关于与django-tenants注册后重定向到租户域吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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