Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Heroku上设置Django应用程序+;亚马逊S3_Django_Heroku_Amazon S3 - Fatal编程技术网

在Heroku上设置Django应用程序+;亚马逊S3

在Heroku上设置Django应用程序+;亚马逊S3,django,heroku,amazon-s3,Django,Heroku,Amazon S3,我第一次成功地在Heroku上部署了一个实时Django应用程序。但是,我没有意识到Heroku不存储媒体文件-我希望管理员能够将图像上传到应用程序-因此我正在尝试设置AmazonS3。这是我第一次做这个设置 1) My settings.py文件包括以下内容 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 's

我第一次成功地在Heroku上部署了一个实时Django应用程序。但是,我没有意识到Heroku不存储媒体文件-我希望管理员能够将图像上传到应用程序-因此我正在尝试设置AmazonS3。这是我第一次做这个设置

1) My settings.py文件包括以下内容

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': "os.path.join(BASE_DIR, 'db.sqlite3')",   # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': '',
        'PASSWORD': '',
        'HOST': '',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '',                      # Set to empty string for default.
    }
}

MEDIA_ROOT = '/media/'

MEDIA_URL = S3_URL + MEDIA_ROOT

STATIC_ROOT = 'staticfiles'

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

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

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
#     'django.template.loaders.eggs.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    # Uncomment the next line for simple clickjacking protection:
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'listing.urls'

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'listing.wsgi.application'

TEMPLATE_DIRS = (
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    'noticeboard',
    'django_extensions',
    'south',
    'PIL',
    'storages',
    'boto',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
)
# Honor the 'X-Forwarded-Proto' header for request.is_secure()
DATABASES['default'] =  dj_database_url.config()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

AWS_ACCESS_KEY_ID = os.environ['AWS_ACCESS_KEY_ID']
ASW_SECRET_ACCESS_KEY = os.environ['AWS_SECRET_ACCESS_KEY']
S3_BUCKET_NAME = os.environ['S3_BUCKET_NAME']

STATICFILES_STORAGE = 'storages.backends.s3boto.s3BotoStorage'
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto.s3BotoStorage'
S3_URL = 'http://s3.amazonaws.com/%s' % S3_BUCKET_NAME
2) 我已经更新了requirements.txt文件,包括
boto
存储
模块

3) 我已经将Heroku
config
文件设置为包含我的bucket名称、AWS密钥和密钥

这是我从管理员上传图像时遇到的错误,似乎它仍在尝试访问Heroku而不是S3上的文件:

Exception Type: OSError
Exception Value:    
[Errno 30] Read-only file system: '/Users'
Exception Location: /app/.heroku/python/lib/python2.7/os.py in makedirs, line 157
Python Executable:  /app/.heroku/python/bin/python
Python Version: 2.7.4
我读过一些关于这方面的博客文章,上面说的都是同样的话,但我一直在想为什么这不起作用