问题
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