I'm using django.core.files.storage.default_storage
function for saving files, but I don't see an option where I would specify that existing ones have to be overwritten. I'm looking for some simplest and cleanest solution, so do I have to write my own function for checking if file exists, and if it does to delete it before saving?
Take a look at django-storages .
It has an overwrite storage backend that does what you're looking for. You just need to update your settings.py to use the OverwriteStorage class:
DEFAULT_FILE_STORAGE = 'storages.backends.overwrite.OverwriteStorage'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.