I have a custom storage
import os
from django.core.files.storage import Storage
class AlwaysOverwriteFileSystemStorage(Storage):
def get_available_name(self, name):
"""
Directly Returns a filename that's
from what user input.
"""
if self.exists(name):
# Remove the existing file
os.remove(name)
# Return the input name as output
return name
I want to know where should I put his AlwaysOverwriteFileSystemStorage.py file and how should by settings.py define DEFAULT_FILE_STORAGE
My Django root folder is /home/username/webapp
When I put DEFAULT_FILE_STORAGE = 'site.storage.AlwaysOverwriteFileSystemStorage', it returns an
Error
Error importing storage module site.storage: “No module named storage”
I am not familiar with Python/Django, any help will be much appreciated. Thank you.
You can put it anywhere, but you should point the path to there in the settings.py
You can put this
storage.pyfile in the root folder (the one that hasmanage.py) and point the path asstorage.AlwaysOverwriteFileSystemStorage