我觉得我已经尝试过将静态和用户上传文件夹与s3一起使用的所有内容。此时,当我运行collectstatic
media
内的所有文件夹最终都在static
内时,即使我非常确定我已为两个要创建的文件夹配置了内容。
我怀疑这与django-filebrowser有关。看来他们已经为存储设置了一些设置,但对于我的生活,我无法弄清楚如何使它们工作:
http://django-filebrowser.readthedocs.org/en/latest/settings.html?highlight=storages
http://django-filebrowser.readthedocs.org/en/latest/admin.html?highlight=storages
有没有人在这里得到django-filebrowser来实际使用s3?如果不是在哪里,你建议我托管用户上传文件?
django-filebrowser它非常贴近我的应用程序。我有它设置为每个图像上传自动创建一个缩略图数组,它工作得很好。如果我无法将它从本地机器上取下来,它对我来说毫无用处。
摘自settings.py
:
from django.conf import settings
import dj_database_url # HEROKU
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
INSTALLED_APPS = (
'grappelli',
'filebrowser',
'django.contrib.contenttypes',
'django.contrib.auth',
'django.contrib.admin',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'debug_toolbar',
'frontpage',
# adding south to try out with django 1.6
'south',
'inplaceeditform',
'inplaceeditform_extra_fields',
'storages',
'boto',
)
# GRAPPELLI SPECIFIC RECOMMENDED ##
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django.contrib.staticfiles.finders.FileSystemFinder',
)
#-------------------------------------------------------------
# DJANGO STORAGES
DEFAULT_FILE_STORAGE = 'addition_interiors_project.s3utils.MediaRootS3BotoStorage'
STATICFILES_STORAGE = 'addition_interiors_project.s3utils.StaticRootS3BotoStorage'
AWS_ACCESS_KEY_ID = 'xxxxxxxxxx'
AWS_SECRET_ACCESS_KEY = 'xxxxxxxxxx'
AWS_STORAGE_BUCKET_NAME = 'xxxxxxxxxx'
AWS_PRELOAD_METADATA = True
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
os.path.join(BASE_DIR, 'media'),
)
MEDIA_ROOT = '/media/'
STATIC_ROOT = '/static/'
S3_URL = 'http://s3.amazonaws.com/%s' % AWS_STORAGE_BUCKET_NAME
STATIC_URL = S3_URL + STATIC_ROOT
MEDIA_URL = S3_URL + MEDIA_ROOT
#-------------------------------------------------------------
#-------------------------------------------------------------
# DJANGO-FILEBROWSER
#-------------------------------------------------------------
FILEBROWSER_VERSIONS_BASEDIR = '_versions'
FILEBROWSER_VERSIONS = {
'admin_thumbnail': {'verbose_name': 'Admin Thumbnail', 'width': 60, 'height': 60, 'opts': 'crop'},
'thumbnail': {'verbose_name': 'Thumbnail (1 col)', 'width': 60, 'height': 60, 'opts': 'crop'},
'small': {'verbose_name': 'Small (2 col)', 'width': 140, 'height': '', 'opts': ''},
'medium': {'verbose_name': 'Medium (4col )', 'width': 300, 'height': '', 'opts': ''},
'big': {'verbose_name': 'Big (6 col)', 'width': 460, 'height': '', 'opts': ''},
'large': {'verbose_name': 'Large (8 col)', 'width': 680, 'height': '', 'opts': ''},
'mega': {'verbose_name': 'Mega (12 col)', 'width': 940, 'height': '', 'opts': ''},
}
FILEBROWSER_ADMIN_VERSIONS = getattr(
settings, 'FILEBROWSER_ADMIN_VERSIONS', ['thumbnail', 'small', 'medium', 'big', 'large', 'mega'])
也是我的s3utils.py:
from storages.backends.s3boto import S3BotoStorage
StaticRootS3BotoStorage = lambda: S3BotoStorage(location='static')
MediaRootS3BotoStorage = lambda: S3BotoStorage(location='media')
我的文件夹结构:
addition_interiors_project
.. manage.py
.. addition_interiors_project
.... addition_interiors_project
....媒体
....静态
....头版
... s3utils.py
... settings.py
... urls.py
... wsgi.py
答案 0 :(得分:0)
您可以使用filebrowser_s3的配置几乎相同。
https://pypi.org/project/filebrowser-s3/
INSTALLED_APPS = [
...,
'filebrowser_s3',
]