我需要什么设置才能使django-filebrowser与s3存储器一起使用? [英] what settings do i need to make django-filebrowser work with s3 storages?
问题描述
我觉得我已经在这里进行了几乎所有的静态化尝试,并且用户上传了文件夹以使用s3.在这一点上,当我运行 collectstatic
时, media
内的所有文件夹最终都位于 static
内,即使我确定我为两个配置了东西要创建的文件夹.
I feel like I've tried just about everything here in getting static and user uploads folders to work with s3. At this point when I run collectstatic
all the folders inside media
end up inside static
, even though I'm pretty sure I configured things for two folders to be created.
我怀疑这与django-filebrowser有关.似乎他们已经对存储进行了一些设置,但是对于我一生来说,我不知道如何使它们工作:
I suspect it's something to do with django-filebrowser. It seems that they have made some settings for storages but for the life of me I can't figure out how to make them work:
http://django-filebrowser.readthedocs.org/zh_CN/latest/settings.html?highlight = storages
http://django-filebrowser.readthedocs.org/zh/latest/admin.html?highlight = storages
这里有没有人得到django-filebrowser来实际使用s3?如果不是,您是否建议我托管用户上传文件?
Has anybody here gotten django-filebrowser to actually work with s3? If not where else do you recommend I host user upload files?
django-filebrowser它非常接近我的应用程序.我将其设置为在每次上传图片时自动创建一个缩略图数组,效果很好.如果我不能从本地计算机上删除它,对我来说就没用了.
django-filebrowser it tied pretty close to my app. I have it setup to automatically create an array of thumbnails with each image upload and it works great. Its useless to me if I can't get it off my local machine though.
摘录自我的 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:
also my s3utils.py:
from storages.backends.s3boto import S3BotoStorage
StaticRootS3BotoStorage = lambda: S3BotoStorage(location='static')
MediaRootS3BotoStorage = lambda: S3BotoStorage(location='media')
我的文件夹结构:
addition_interiors_project
.. manage.py
..manage.py
.. addition_interiors_project
.... addition_interiors_project
.... media
.... static
....首页
.... s3utils.py
....s3utils.py
.... settings.py
....settings.py
.... urls.py
....urls.py
.... wsgi.py
....wsgi.py
推荐答案
您可以使用filebrowser_s3进行的配置几乎相同.
You can use filebrowser_s3 configuration is almost the same.
https://pypi.org/project/filebrowser-s3/ >
INSTALLED_APPS = [
...,
'filebrowser_s3',
]
这篇关于我需要什么设置才能使django-filebrowser与s3存储器一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!