【发布时间】:2017-07-06 22:21:39
【问题描述】:
我是 Django 的新手。我做了一个本地演示,它运行没有问题,但下一步是在 AWS Elastic beanstalk 上部署 Django 应用程序,我正在尝试。
我有这个环境: ~/Python_Env/MiEntorno
还有这个项目: ~/ProyectosDjango/Refugio
我目前的 Django 项目结构是这样的:
requirements.txt
.ebextensions
|-01-django_env.config
.elasticbeanstalk
|-config.yml
.gitignore
custom_storage.py
manage.py
Refugio
|__init__.py
|-settings
|-urls.py
|-wsgi.py
|-apps
|-templates
|-static
执行此命令时出现此错误:(Mi Entorno) /ProyectosDjango/Refugio> manage.py collectstatic 或 manage.py runserver
“无法导入 Django。您确定它已安装并可用 你的 PYTHONPATH 环境变量?您是否忘记激活 虚拟环境?”
我把它放在我的 -01-django_env.config 中:
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "Refugio.settings"
PYTHONPATH: "/opt/python/current/app/Refugio:$PYTHONPATH"
"aws:elasticbeanstalk:container:python"
WSGIPath: "Refugio/Refugio/wsgi.py"
在设置中我编辑数据库并添加:
STATICFILES_LOCATION = 'static'
MEDIAFILES_LOCATION = 'media'
AWS_STORAGE_BUCKET_NAME = 's3.refugioprueba.com'
AWS_ACCESS_KEY_ID = 'xxx'
AWS_SECRET_ACCESS_KEY = 'yy/xxx/'
STATICFILES_STORAGE = 'custom_storages.StaticStorage'
DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage'
AWS_S3_CUSTOM_DOMAIN = '%s.s3-us-west-1.amazonaws.com' % AWS_STORAGE_BUCKET_NAME
AWS_S3_SECURE_URLS = False
from boto.s3.connection import ProtocolIndependentOrdinaryCallingFormat
AWS_S3_CALLING_FORMAT = ProtocolIndependentOrdinaryCallingFormat
from boto.s3.connection import S3Connection
S3Connection.DefaultHost = 's3.us.west-1.amazonaws.com'
STATIC_URL = "http://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, STATICFILES_LOCATION)
MEDIA_URL = "http://%s/%s/" % (AWS_S3_CUSTOM_DOMAIN, MEDIAFILES_LOCATION )
WSGI_APPLICATION = 'Refugio.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'ebdb',
'USER': 'root',
'PASSWORD': 'XXX',
'HOST': 'XXXrds.amazonaws.com',
'PORT': 3306,
}
}
【问题讨论】:
标签: python django amazon-web-services