我觉得我已经尝试了这里的所有东西,让静态和用户上传文件夹与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
....media
....static
....frontpage
....s3utils.py
....settings.py
....urls.py
....wsgi.py
发布于 2020-12-14 08:07:36
您可以使用filebrowser_s3配置几乎是相同的。
https://pypi.org/project/filebrowser-s3/
INSTALLED_APPS = [
...,
'filebrowser_s3',
]https://stackoverflow.com/questions/22775435
复制相似问题