1👍
✅
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'
0👍
You can delete the file and then save, look at this:
from django.core.files.storage import default_storage
from django.core.files.base import ContentFile
file = ContentFile("Some text", name="data.txt")
path = f"/path/to/{file.name}"
if default_storage.exists(path):
default_storage.delete(path)
default_storage.save(path, file)
- Prefetch alternative vs Filter directly in template
- The image in django doesn't work
- Unexpected kawrgs ,TypeError at /courses/course/1/1/
- How to ajaxable validate a PasswordChangeForm?
Source:stackexchange.com