5
5
6
6
import hashlib
7
7
8
+ from django import VERSION
8
9
from django .conf import settings
9
10
from django .contrib .staticfiles .storage import staticfiles_storage
11
+ from django .core .files .storage import storages
10
12
from django .core .exceptions import ObjectDoesNotExist
11
13
from django .utils .module_loading import import_string
12
14
@@ -33,11 +35,22 @@ def get_profile_image_storage():
33
35
An instance of the configured storage backend.
34
36
"""
35
37
config = getattr (settings , 'PROFILE_IMAGE_BACKEND' , {})
36
- storage_class_path = config .get ('class' ) or getattr (
37
- settings , 'DEFAULT_FILE_STORAGE' , 'django.core.files.storage.FileSystemStorage'
38
- )
38
+ storage_class_path = config .get ('class' )
39
+ options = config .get ('options' , {})
40
+
41
+ if not storage_class_path :
42
+ # Django 5.x STORAGES fallback
43
+ if django_version [0 ] >= 5 and hasattr (settings , 'STORAGES' ) and 'default' in settings .STORAGES :
44
+ return storages ['default' ]
45
+ else :
46
+ # Legacy fallback
47
+ storage_class_path = getattr (
48
+ settings , 'DEFAULT_FILE_STORAGE' ,
49
+ 'django.core.files.storage.FileSystemStorage'
50
+ )
51
+
39
52
storage_class = import_string (storage_class_path )
40
- return storage_class (** config . get ( ' options' , {}) )
53
+ return storage_class (** options )
41
54
42
55
43
56
def _make_profile_image_name (username ):
0 commit comments