Saeed Esmaili
Saeed Esmaili

Reputation: 843

Changing the settings file when using django and gunicorn together

I've deployed my Django project using this tutorial and it works fine.

Now I want to split the settings file and have multiple settings in development and production environments. I created a settings directory and added these files into the directory:

my_project/
    manage.py
    my_project/
       __init__.py
       urls.py
       wsgi.py
       settings/
           __init__.py
           base.py
           dev.py
           prod.py

The base.py is same as former settings.py (that was working fine). I imported base.py and added DEBAG=False and ALLOWED_HOSTS to prod.py.

How can I tell the gunicorn to run my application with prod settings?

The gunicorn.service file, based on the tutorial is like this:

[Unit]
Description=gunicorn daemon
After=network.target

[Service]
User=sammy
Group=www-data
WorkingDirectory=/home/sammy/myproject
ExecStart=/home/sammy/myproject/myprojectenv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/sammy/myproject/myproject.sock myproject.wsgi:application

[Install]
WantedBy=multi-user.target

Upvotes: 0

Views: 2313

Answers (2)

Saeed Esmaili
Saeed Esmaili

Reputation: 843

The problem was the settings.pyc file in the project directory. Removing that file, fixed the problem.

Upvotes: 0

Kamil
Kamil

Reputation: 1386

You can set DJANGO_SETTINGS_MODULE environment variable for this, as mentioned here.

So you can try to add something like:

Environment="DJANGO_SETTINGS_MODULE=my_project.settings.prod"

to [Service] section.

Upvotes: 7

Related Questions