【问题标题】:AWS and Django: "Couldn't import Django"AWS 和 Django:“无法导入 Django”
【发布时间】: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 collectstaticma​​nage.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


    【解决方案1】:

    您确定它已安装在环境中吗?如pip install django(或您使用的任何特定版本)?或者pip install -r requirements.txt 如果它在您的requirements.txt 文件中? EBS 通常会自动安装requirements.txt 依赖项,因此将其放在那里是最安全的

    【讨论】:

      猜你喜欢
      • 2021-02-04
      • 2018-06-26
      • 1970-01-01
      • 1970-01-01
      • 2011-07-01
      • 2018-02-22
      • 2014-08-11
      • 1970-01-01
      相关资源
      最近更新 更多