Innovate anywhere, anytime Your cloud-based dev studio.

How to Maintain User Session Across Sub Domains in Django


Nowadays, people are using wildcard domains to provide same user experience across different domains. Using subdomains, we can be able to host multiple sites with the same domain name with the same code in a less time.

To enable wildcard subdomains for your site, you should add CNAME record like.


With this, you can be able to access your site domain with,, etc.

After enabling wildcard domains, you should update your nginx file to accept wildcard domain requests.

server {

    listen       YOUR_IP_ADDRESS;

    server_name, *;



With the above nginx settings, you're able to access requests from wildcard domains like normal domain.

Now you've different wildcard domains for your site( When user login into, redirects to the wildcard domain( we should maintain same user session across subdomains. By default, django application isn't maintaining same user session across subdomains. To maintain this, we should add following details to the application settings file.



Here SESSION_COOKIE_DOMAIN should start with '.' character followed by DOMAIN_NAME. This will handle and enable user session/cookies across wildcard domains(,,


In local development, your domain should start .com or .io update your localhost with any other domains in /etc/hosts file:

And your settings file should be



With the above settings, django application will maintain user session across subdomains.