Skip to content

Commit 439f4fd

Browse files
authored
Fix import error for django 4.0 (#17)
The force_text function has been deprecated from django 4.0 and is replaced by force_str. To work with both django 4.0 and earlier versions, we try to import force_text, and if that fails, we import force_str and creates an alias function called force_text.
1 parent aae0a8a commit 439f4fd

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

compressor/cache.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@
88
import six
99
from django.core.cache import caches
1010
from django.core.files.base import ContentFile
11-
from django.utils.encoding import force_text, smart_bytes
11+
from django.utils.encoding import smart_bytes
1212
from django.utils.functional import SimpleLazyObject
1313

14+
try:
15+
from django.utils.encoding import force_text
16+
except ImportError:
17+
from django.utils.encoding import force_str
18+
force_text = force_str
19+
1420
from compressor.conf import settings
1521
from compressor.storage import default_storage
1622
from compressor.utils import get_mod_func

0 commit comments

Comments
 (0)