Amazon EC2 - S3 - Django ImageField问题

时间:2015-03-05 20:00:55

标签: django django-models amazon-ec2 amazon-s3

我想使用S3作为Django应用程序的文件存储。我有EC2实例设置。它正常工作,但是当我从管理页面上传文件时,这些文件不会出现在S3存储桶上。

当我检查上传文件的URL时,它会告诉我S3存储桶URL。

这是我的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'],
  }
}

BASE_DIR = os.path.dirname(os.path.dirname(__file__))

STATIC_URL = '/static/'
MEDIA_URL='/media/'
STATIC_ROOT = os.path.join(BASE_DIR, "..", "static")
MEDIA_ROOT=os.path.join(BASE_DIR, "..", "media")

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'

AWS_S3_ACCESS_KEY_ID = 'access key'
AWS_S3_SECRET_ACCESS_KEY = 'coolsecret'
AWS_STORAGE_BUCKET_NAME = 'elasticbeanstalk-eu-west-1-4234323423'

这是我的urls.py:

from django.conf.urls import patterns, include, url
from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

urlpatterns = patterns('',
    url(r'^admin/', include(admin.site.urls)),
    #my other urls
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

urlpatterns += staticfiles_urlpatterns()

0 个答案:

没有答案