Django存储:导入错误 - 没有名为存储的模块

tld*_*ldr 7 django amazon-s3 boto python-django-storages

我正在尝试使用Django的存储后端(对于BotoS3)

settings.py:

INSTALLED_APPS = (
...
'storages',
...
)
Run Code Online (Sandbox Code Playgroud)

http://django-storages.readthedocs.org/en/latest/index.html所示.

和,requirements.txt:

django-storages==1.1.8
Run Code Online (Sandbox Code Playgroud)

但我得到错误:

django.core.exceptions.ImproperlyConfigured: ImportError storages: No module named storages
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

sha*_*aan 14

您可能会在virtualenv中将virtualenv之外的软件包安装到默认的python安装中.确保你没有这样做.

  • 请包含有关如何“确保您没有这样做”的上下文。 (2认同)

Dan*_*ong 9

如果您'storages'在您的INSTALLLED_APPSdjango-storages中包含了此错误requirements.txt,请检查您的STATICFILES_STORAGE变量。

对于以前版本的django-storages,这应该设置为:

STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
Run Code Online (Sandbox Code Playgroud)

对于较新版本的django-storages,包使用boto3代替,boto并且此变量应设置为:

STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
Run Code Online (Sandbox Code Playgroud)

如果您使用任一版本并且您的DEFAULT_FILE_STORAGE设置配置不正确,您将收到导入错误。

可以在django-storages 文档中找到正确的设置


小智 5

我有同样的问题。就我而言,我解决了这个问题

pip install django-storages

Collecting django-storages
  Downloading django_storages-1.6.5-py2.py3-none-any.whl (47kB)
    100% |################################| 51kB 358kB/s
Installing collected packages: django-storages
Successfully installed django-storages-1.6.5
Run Code Online (Sandbox Code Playgroud)

它是在我的虚拟环境中执行的。