I am using django-storages to serve media files on Dropbox
. But I cannot get it working (media files are still stored in local server).
I've installed dropbox and django-storages, and created an app with permission type:app folder
, then added related settings.
Here's my settings:
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',
)
To be able to upload the media files to Dropbox (and reading them) what has to be changed in the settings code?
Ok, found the problem! The settings are correct, the problem was that for some reason I was using a custom storage for my FileField
! All I had to do was removing the storage=...
:
file = models.FileField(upload_to=some_path, storage=CustomStorage())
to
file = models.FileField(upload_to=some_path)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With