如何将自定义存储连接到django

问题描述 投票:0回答:1

我正在编写一个自定义存储模块,以使用远程seafile服务器作为django(django-cms)安装的存储。

文件

seafile.py
位于项目文件夹中:

enter image description here

存储类已使用 jupyter Notebook 进行测试并且正在运行。

问题:我无法将我的存储连接到django(本地,开发服务器),它仍然在媒体文件夹中本地保存图片,并且根本不使用我的存储。

settings.py

from .seafile import MyStorage

...

我尝试过的事情:

DEFAULT_FILE_STORAGE = "MyStorage"
DEFAULT_FILE_STORAGE = "seafile.MyStorage"
DEFAULT_FILE_STORAGE = MyStorage
DEFAULT_FILE_STORAGE = MyStorage()

当然我已经看到并尝试了建议的解决方案(https://docs.djangoproject.com/en/5.1/howto/custom-file-storage/#use-your-custom-storage-engine)但也失败了.

我错过了什么?预先感谢您!

python django storage
1个回答
0
投票

两个更改使自定义存储发挥作用:

settings.py

STORAGES = {
    "default": {
        "BACKEND": "seafile.seafile.MyStorage",
        "OPTIONS": {...},
    },
    "staticfiles": {
        "BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
    }
}

重要提示:将

"seafile.MyStorage"
更改为
"seafile.seafile.MyStorage"
以反映
"folder.file.class"

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.