Quantcast
Channel: Active questions tagged amazon-ec2 - Stack Overflow
Viewing all articles
Browse latest Browse all 29417

django on AWS with multiple settings file

$
0
0

Well, I had one setting file before and it was working perfectly both in local and AWS of course with both the database configuration in one setting file. When ever I use to push my code on AWS I would comment my local db configuration and then push. So for sure, that's annoying. I can't comment and uncomment constantly both the database configuration in one file.

Therefore, I decided to have 2 setting files. one for the local and the other for AWS.

Once I pulled the code into AWS server and run migrations

python manage.py migrate --settings=settings.staging

It worked and migrated. By the way, this is the setting file which resides my RDS configuration. Now the moment I hit the endpoints via postmant the output is as

OperationalError at /account/v1/login
could not connect to server: Connection refused
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?

means it is still reading the default settings file. How come I make the server run this particular staging setting file. Do I have to declare it on nginx, supervisor or gunicorn? I'm using these 3 services as well.

Below is my settings file for staging.

from .base import *

# --------------- AWS RDS ---------------
DATABASES = {
    'default': {
        # 'ENGINE': 'django.db.backends.sqlite3',
        # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'db name here',
        'HOST': 'RDS host here',
        'USER': 'postgres',
        'PASSWORD': 'pass here',
        'PORT': '5432'
    }
}

This is my complete staging.py file. which only have this while the rest of the setting is being imported from base.py which is a default setting file. Also it has the local settings.

Any recommendations?

This is also what I've tried.

import socket

hostname = socket.gethostname()
if hostname == "staging":
     from settings.staging import *

Thank you


Viewing all articles
Browse latest Browse all 29417

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>