gpt4 book ai didi

python - Elastic Beanstalk 不创建 RDS 参数

转载 作者:可可西里 更新时间:2023-11-01 07:45:10 25 4
gpt4 key购买 nike

我正在按照本教程努力在 AWS 上创建 Django 应用程序。

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_Python_django.html

我能够让一切都与本地 sqlite 数据库一起工作,但我正在尝试将应用程序推送到生产服务器。在执行 Elastic Beanstalk 初始化过程时,我选择创建一个 RDS 实例。

我的 mysite/settings.py 看起来像这样:

导入操作系统

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': os.environ['RDS_DB_NAME'],
'USER': os.environ['RDS_USERNAME'],
'PASSWORD': os.environ['RDS_PASSWORD'],
'HOST': os.environ['RDS_HOSTNAME'],
'PORT': os.environ['RDS_PORT'],
}
}

此时我应该可以访问 RDS 参数,但我没有。 manage.py 文件变得无响应。

(djangodev)laptop-id:mysite user-name$ python manage.py runserver
Unknown command: 'runserver'
Type 'manage.py help' for usage.

(djangodev)laptop-id:mysite use-name$ python manage.py
Usage: manage.py subcommand [options] [args]

Options:
-v VERBOSITY, --verbosity=VERBOSITY
Verbosity level; 0=minimal output, 1=normal output,
2=verbose output, 3=very verbose output
--settings=SETTINGS The Python path to a settings module, e.g.
"myproject.settings.main". If this isn't provided, the
DJANGO_SETTINGS_MODULE environment variable will be
used.
--pythonpath=PYTHONPATH
A directory to add to the Python path, e.g.
"/home/djangoprojects/myproject".
--traceback Print traceback on exception
--version show program's version number and exit
-h, --help show this help message and exit
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 376, in execute
sys.stdout.write(self.main_help_text() + '\n')
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 242, in main_help_text
for name, app in six.iteritems(get_commands()):
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 109, in get_commands
apps = settings.INSTALLED_APPS
File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 132, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/andrewcopp/Developer/mysite/mysite/settings.py", line 17, in <module>
'NAME': os.environ['RDS_DB_NAME'], # Or path to database file if using sqlite3.
File "/tmp/djangodev/bin/../lib/python2.7/UserDict.py", line 23, in __getitem__
raise KeyError(key)
KeyError: 'RDS_DB_NAME'

知道我可能忽略了什么吗?我可以提供更多信息来澄清事情

最佳答案

您需要在本地回退到设置中的不同数据库。

在您的 settings.py 文件中,将 DATABASE 变量替换为:

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'],
}
}

现在在与您的 settings.py 相同的目录中创建一个 local_settings.py 并输入以下代码:

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 = ()

现在将您的 local_settings.py 文件添加到您的 .gitignore 文件中。

运行 $ python manage.py syncdb 现在您可以在本地运行 django 服务器。

其中大部分是从我发现的这篇博文中复制意大利面: http://grigory.ca/2012/09/getting-started-with-django-on-aws-elastic-beanstalk/

关于python - Elastic Beanstalk 不创建 RDS 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18159079/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com