问题
My deployment script overwrites the media and source directories which means I have to move the uploads directory out of the media directory, and replace it after the upload has been extracted.
How can I instruct django to upload to /uploads/ instead of /media/?
So far I keep getting django Suspicious Operation errors! :(
I suppose another solution might be a symlink?
Many thanks, Toby.
回答1:
I did the following:
from django.core.files.storage import FileSystemStorage
upload_storage = FileSystemStorage(location=UPLOAD_ROOT, base_url='/uploads')
image = models.ImageField(upload_to='/images', storage=upload_storage)
UPLOAD_ROOT
is defined in my settings.py
file: /foo/bar/webfolder/uploads
来源:https://stackoverflow.com/questions/1729051/django-upload-to-outside-of-media-root