我正在使用django-storages
在Dropbox
上投放媒体文件。但我无法让它工作(mdeia文件仍然存储在本地服务器中)。
我已经安装了dropbox和django-storage,并使用permission type:app folder
创建了一个应用,然后添加了相关设置。
这是我的设置:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
DEBUG = False
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_filters',
'website',
'storages',
)
# for dropbox
DEFAULT_FILE_STORAGE = 'storages.backends.dropbox.DropBoxStorage'
DROPBOX_OAUTH2_TOKEN = 'my_generated_token_from_dropbox'
DROPBOX_ROOT_PATH = 'media'
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)
为了能够将媒体文件上传到Dropbox(并阅读它们),必须在设置代码中更改哪些内容?
由于
答案 0 :(得分:1)
FileField
!我所要做的就是删除storage=...
:
file = models.FileField(upload_to=some_path, storage=CustomStorage())
到
file = models.FileField(upload_to=some_path)