AWS Beanstalk Django / Python Running Local Issue

时光怂恿深爱的人放手 提交于 2019-12-03 21:57:45

It took a lot of digging around but I found a solution. You need a local fallback to a different database.

In your settings.py file, replace the DATABASE variable with this:

DATABASES = {}

try:
    from local_settings import *
except ImportError, e:
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': os.environ['RDS_DB_NAME'],
            'USER': os.environ['RDS_USERNAME'],
            'PASSWORD': os.environ['
            'HOST': os.environ['RDS_HOSTNAME'],
            'PORT': os.environ['RDS_PORT'],
        }
    }

Now create a local_settings.py in the same directory as your settings.py and enter the following code:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'db.djangodb',
        'USER': '',
        'PASSWORD': '',
        'HOST': '',
        'PORT': '',
    }
}

MEDIA_ROOT = ''
MEDIA_URL = ''
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = ()
TEMPLATE_DIRS = ()

Now add your local_settings.py file to your .gitignore file.

Run $ python manage.py syncdb and now you can run the django server locally.

Most of this is copy pasta from this blog post I found: http://grigory.ca/2012/09/getting-started-with-django-on-aws-elastic-beanstalk/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!