Redirect to tenant domain after signup with django-tenants?

折月煮酒 提交于 2020-01-25 09:16:06

问题


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})

来源:https://stackoverflow.com/questions/59436447/redirect-to-tenant-domain-after-signup-with-django-tenants

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!