J
J
Jekson2020-03-11 16:40:39
Django
Jekson, 2020-03-11 16:40:39

Setting up django wsgi.py for multiple servers?

There is a configured server on Ubuntu18, nginx, uwsgi (I'll call it stage)
In Django, the settings (settings.py) are separated separately for development, staging.
base.py
ALLOWED_HOSTS = ['127.0.0.1']

development.py

from .base import *

DEBUG = True


staging.py
from .base import *
ALLOWED_HOSTS += 'staging.site.com'
DEBUG = False


wsgi.py
import os

from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'solution_project.settings.staging')
application = get_wsgi_application()


That is, on the wsgi server, it uses the settings from staging.py.

It all works.

Now I need to add the same server but with a different domain

, I add a new file with

test.py settings
<code>from .base import *
ALLOWED_HOSTS += 'test.site.com'
DEBUG = False</code>


But what to do with the project's uwsgi.py file?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2020-03-11
@Lepilov

I've been doing this for a long time, it's terribly inconvenient. It is better to have the same code for everything, and make differences through environment variables, for example

DEBUG = os.environ.get('PROJECT_NAME_DJANGO_DEBUG')

PS this is just an example, there are libraries that environ translate bool, list, etc. into normal types.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question