我正在使用Heroku部署我用Django 3.1.2(python 3.6.12)制作的应用程序,我正在使用Cloudinary存储上传的图像。
我遇到了ModuleNotFoundError(如下所示),因为cloudinary-storage导入了django.utils.six,但Django 3.0不支持django. utils. six。
我做了一些研究,但没有找到一个有效的答案。一个建议是降级到Django 2--但是当我这样做的时候,我开始收到许多其他的错误,因为我的应用程序的其他部分,所以我不想走这条路,如果可能的话。
所以现在我正试图找出一种方法,我可以一起使用Django 3和Cloudinary,并解决Django 3不支持django. utils. six的问题。任何帮助/建议将不胜感激
下面是回溯:
Django Version: 3.1.2
Python Version: 3.6.12
Installed Applications:
['users.apps.UsersConfig',
'point_system.apps.PointSystemConfig',
'crispy_forms',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'cloudinary_storage',
'cloudinary']
Installed Middleware:
('whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py", line 179, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/views/generic/base.py", line 70, in view
return self.dispatch(request, *args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/views/generic/base.py", line 98, in dispatch
return handler(request, *args, **kwargs)
File "/app/.heroku/python/lib/python3.6/site-packages/django/views/generic/list.py", line 157, in get
context = self.get_context_data()
File "/app/point_system/views.py", line 144, in get_context_data
temp.append(p.image.url)
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/models/fields/files.py", line 62, in url
return self.storage.url(self.name)
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 240, in inner
self._setup()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/files/storage.py", line 364, in _setup
self._wrapped = get_storage_class()()
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/files/storage.py", line 359, in get_storage_class
return import_string(import_path or settings.DEFAULT_FILE_STORAGE)
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/module_loading.py", line 17, in import_string
module = import_module(module_path)
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
<source code not available>
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
<source code not available>
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
<source code not available>
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
<source code not available>
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
<source code not available>
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
<source code not available>
File "/app/.heroku/python/lib/python3.6/site-packages/cloudinary_storage/storage.py", line 17, in <module>
from django.utils.six.moves.urllib.parse import urlsplit, urlunsplit, unquote
Exception Type: ModuleNotFoundError at /
Exception Value: No module named 'django.utils.six'
我发现的一些答案不起作用:
ModuleNotFoundError: No module named 'django.utils.six'
ImportError:无法从'django.utils'导入名称'six'
https://github.com/jazzband/django-sortedm2m/issues/151
提前感谢您的帮助,请让我知道,如果我需要提供任何更多的信息!
1条答案
按热度按时间insrf1ej1#
我在从Django 2升级到Django 4时也遇到了同样的问题。看起来你可以从python本身导入它们,而不需要像这样使用django:
这是文档