K
K
KirillTrueno2022-04-03 21:36:52
Python
KirillTrueno, 2022-04-03 21:36:52

How to get the domain name in index.wsgi (python)?

There is a site on django, two domains are attached to it: foo.ru and bar.ru.
Each domain has its own settings.py, i.e. settings_foo.py and settings_bar.py.
In index.wsgi, you need to set different values ​​for os.environ['DJANGO_SETTINGS_MODULE'] depending on the domain.

index.wsgi:

import os, sys
from django.core.wsgi import get_wsgi_application

sys.path.insert(0, '../news')
sys.path.insert(1, '../env/lib/python3.9/site-packages')

domain = ????????????????????????????????

if domain == 'foo.ru':
    os.environ['DJANGO_SETTINGS_MODULE'] = 'news.settings_foo'
elif domain == 'bar.ru':
    os.environ['DJANGO_SETTINGS_MODULE'] = 'news.settings_bar'

application = get_wsgi_application()


How to find out on which domain the user opened the site?
Or maybe there is some simpler and smarter solution?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Kravtsov, 2022-04-07
@Kosta6808

1 You can insert return into each condition and return, for example, a string with the name of the
domain
... receiving a request with a domain name, check if it is in the list of names and respond accordingly

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question