Skip to main content
 首页 » 编程设计

python之使用 azure 作为 Django 的存储后端(使用 django-storages)

2024年10月24日36jpfss

我正在使用 django-storages,我过去曾使用它来处理 AWS S3。但是在使用 Microsoft Azure 时,我遇到了在谷歌上没有返回任何结果的错误。

我正在使用 python 3 和 Django 1.8.4 进行开发。我正在使用 django-storages 和 django-storages-redux 来支持 python 3。

当调用 ./manage.py collectstatic 并输入 yes 时,我得到两个(!)错误:

Traceback (most recent call last): 
  File "/Users/mac/.virtualenvs/bratwurst/lib/python3.4/site-packages/storages/backends/azure_storage.py", line 44, in exists 
    self.connection.get_blob_properties( 
  File "/Users/mac/.virtualenvs/bratwurst/lib/python3.4/site-packages/storages/backends/azure_storage.py", line 34, in connection 
    self._connection = azure.storage.BlobService( 
AttributeError: 'module' object has no attribute 'BlobService' 
 
During handling of the above exception, another exception occurred: 
 
Traceback (most recent call last): 
  File "./manage.py", line 10, in <module> 
    execute_from_command_line(sys.argv) 
  File "/Users/mac/.virtualenvs/bratwurst/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line 
    utility.execute() 
  File "/Users/mac/.virtualenvs/bratwurst/lib/python3.4/site-packages/django/core/management/__init__.py", line 330, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
  File "/Users/mac/.virtualenvs/bratwurst/lib/python3.4/site-packages/django/core/management/base.py", line 393, in run_from_argv 
    self.execute(*args, **cmd_options) 
  File "/Users/mac/.virtualenvs/bratwurst/lib/python3.4/site-packages/django/core/management/base.py", line 444, in execute 
    output = self.handle(*args, **options) 
  File "/Users/mac/.virtualenvs/bratwurst/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 168, in handle 
    collected = self.collect() 
  File "/Users/mac/.virtualenvs/bratwurst/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 107, in collect 
    handler(path, prefixed_path, storage) 
  File "/Users/mac/.virtualenvs/bratwurst/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 305, in copy_file 
    if not self.delete_file(path, prefixed_path, source_storage): 
  File "/Users/mac/.virtualenvs/bratwurst/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 218, in delete_file 
    if self.storage.exists(prefixed_path): 
  File "/Users/mac/.virtualenvs/bratwurst/lib/python3.4/site-packages/storages/backends/azure_storage.py", line 46, in exists 
    except azure.WindowsAzureMissingResourceError: 
AttributeError: 'module' object has no attribute 'WindowsAzureMissingResourceError' 

我遵循了将 django-storages 与 azure here 结合使用的微不足道的说明。 .

知道是什么导致了这个错误吗?有没有人成功部署了一个以 azure 作为存储和静态文件后端的 django 1.8 应用程序?

编辑:我在 django-storages 模块中做了一些改动: 使用

import azure.storage.blob 
self._connection = azure.storage.blob.blobservice.BlobService( 

不仅仅是

self._connection = azure.storage.BlobService( 

但现在我遇到了不同的错误,这让我相信这个问题实际上更深层次。

请您参考如下方法:

我发现了问题:

django-storages-redux 已经过时并且与最新版本的 azure sdk 不兼容

作者的拉取请求正在处理中:

https://github.com/jschneier/django-storages/pull/86

我在这里做了自己的快速修复:

https://github.com/schumannd/django-storages