0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Django 5.2 でのDEFAULT_FILE_STORAGEの指定方法

Posted at

Django 4.2 LTS までは DEFAULT_FILE_STORAGE にアップロードファイルを扱うストレージクラスを指定することで、ローカルフォルダ以外のストレージに対応することができました。

Django 5.2 LTS では DEFAULT_FILE_STORAGE は廃止されているため、4.2でも導入されていた STORAGES 設定を利用する必要があります。

image.png

STORAGES では アップロードファイルだけではなく、静的ファイル (staticfiles) の扱いも定めることができます。

これまでの設定を置き換えるには次のように書き換えると良いです。

旧方式
DEFAULT_FILE_STORAGE = "app.storage_backends.MediaStorage"
新方式
STORAGES = {
    "default": {
        "BACKEND": "app.storage_backends.MediaStorage",
    },
    "staticfiles": {
        "BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
    },
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?