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.


    DOMAIN_NAME = ""

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


    DOMAIN_NAME = ""

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

Posted On 04 June 2019 By MicroPyramid

About Micropyramid

Micropyramid is a software development and cloud consulting partner for enterprise businesses across the world. We work on python, Django, Salesforce, Angular, Reactjs, React Native, MySQL, PostgreSQL, Docker, Linux, Ansible, git, amazon web services. We are Amazon and salesforce consulting partner with 5 years of cloud architect experience. We develop e-commerce, retail, banking, machine learning, CMS, CRM web and mobile applications.

Need any Help in your Project?Let's Talk


Subscribe To our news letter

Subscribe and Stay Updated about our Webinars, news and articles on Django, Python, Machine Learning, Amazon Web Services, DevOps, Salesforce, ReactJS, AngularJS, React Native.
*We don't provide your email contact details to any third parties