Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8809985
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:00:48+00:00 2026-06-14T03:00:48+00:00

I am trying to implement a multi-tenant application in Django and PostgreSQL, with a

  • 0

I am trying to implement a multi-tenant application in Django and PostgreSQL, with a separate (but identical) schema for every tenant.

I select the tenant schema with:

cursor.execute('SET search_path TO ' + schemas)

And I have a middleware that selects which schema to use based on the hostname, so it would work something like this:

foo.mysite.com --> use schema 'client_moo'
bar.mysite.com --> use schema 'client_bar'

This works in principle, that is in simple cases (simple db lookups)

However, things start to break down when I try to log in. Each tenant should have its own, separate log in page, so foo.mysite.com would be distinct from bar.mysite.com which would be distinct from mysite.com.

However, trying to login into the admin app from a subdomain results in a redirect back to the login page.

Here is what happens:

  • mysite.com logs in fine (schema: public)
  • foo.mysite.comn instead of logging in will redirect (HTTP 302) back to itself (foo.mysite.com) (schema: client_foo)

Forcing the schema to always be client_foo will result in mysite.com working (that is, logging in on the client_foo schema), but foo.mysite.com still not working.


Removing schema selection altogether (so that it is always on public schema) will make both URLs log in fine.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:00:49+00:00Added an answer on June 14, 2026 at 3:00 am

    1) Did you set up your session cookie properly to support cross-domain sessions? See: https://docs.djangoproject.com/en/dev/topics/http/sessions/#session-cookie-domain

    2) If you’re using DB session storage (which is the default), then switching schema will most likely result in Django not being able to fetch the session from the database (depends on order of your middleware).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to implement a multi-tenant application, that is - data of all
Im trying to implement multi-threading in my application that makes a lot of float
I am trying to implement multi-threading in my Java Mandelbrot application: This is what
Trying to implement LoaderManager + CursorLoader. In onFinish method adapter should swap its cursor
Trying to implement 3-layer (not: tier, I just want to separate my project logically,
Hi fellow android developers, I'm trying to implement a multi-pane layout as described here
I am trying to implement MVVM (Model View ViewModel) pattern for my WinForms application.
I've been trying to implement a dynamic multi-model form with accepts_nested_attributes_for in my rails
I am trying to implement core data entities in a multi-threaded environment. I understand
I'm trying to implement multi-threading as suggested here: Spawn Multiple Threads for work then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.