matulik
matulik

Reputation: 41

One Django app instance for multiple domains

I try to create an Django app which will work for multiple domains with single app instance.

For example:

I used Django Site framework to associate user with domains - content restriction for user in specific domains works fine.

Additionally, I used SESSION_COOKIE_DOMAIN parameter in settings.py for "share" cookie between domains and, unfortunately, it only works for subdomains. For example, after set:

SESSION_COOKIE_DOMAIN = '.group.com'

and after I wrote simple middleware, I'm able to meet the requirements that I wrote above but only for subdomains, like 'one.group.com', 'two.group.com', 'three.group.com'.

I was looking for solution for handle that, but I haven't found an answer for newest Django 3.x framework.

Is there any way to handle that like I explained?

Upvotes: 3

Views: 2248

Answers (1)

Ali Yaman
Ali Yaman

Reputation: 238

I think "django-hosts" package for you.

Firstly, you should give permission some domain.

ALLOWED_HOSTS = [example1.com,example2.com,example3.com]

And than, you can use django-hosts

from django_hosts import patterns, host
host_patterns = patterns('path.to',
    host(r'api', 'api.urls', name='api'),
    host(r'beta', 'beta.urls', name='beta'),
)

You can see more information -> https://github.com/jazzband/django-hosts

Upvotes: 2

Related Questions