gpt4 book ai didi

django - python 3中的S3BotoStorage

转载 作者:行者123 更新时间:2023-12-04 14:44:10 24 4
gpt4 key购买 nike

我已经设置了我的 Django 项目来将静态文件和用户上传的文件存储到 Amazon S3 中。为了实现这一点,我遵循了此处找到的示例 https://ashokfernandez.wordpress.com/2014/03/11/deploying-a-django-app-to-amazon-aws-with-nginx-gunicorn-git/ :

产品.py

INSTALLED_APPS += ('storages',)
AWS_STORAGE_BUCKET_NAME = "project"
STATICFILES_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
S3_URL = 'http://%s.s3.amazonaws.com/' % AWS_STORAGE_BUCKET_NAME
STATIC_URL = S3_URL

但是当我尝试运行时 manage.py collectstatic -v 0 --noinput我收到此错误:
 Traceback (most recent call last):
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/storages/backends/s3boto.py", line 7, in <module>
from cStringIO import StringIO
ImportError: No module named 'cStringIO'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/ubuntu/webapps/project/manage.py", line 14, in <module>
execute_from_command_line(sys.argv)
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/core/management/__init__.py", line 238, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/core/management/__init__.py", line 42, in load_command_class
return module.Command()
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 58, in __init__
self.storage.path('')
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/utils/functional.py", line 224, in inner
self._setup()
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/contrib/staticfiles/storage.py", line 391, in _setup
self._wrapped = get_storage_class(settings.STATICFILES_STORAGE)()
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/core/files/storage.py", line 303, in get_storage_class
return import_string(import_path or settings.DEFAULT_FILE_STORAGE)
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/django/utils/module_loading.py", line 26, in import_string
module = import_module(module_path)
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/ubuntu/.virtualenvs/project/lib/python3.4/site-packages/storages/backends/s3boto.py", line 9, in <module>
from StringIO import StringIO # noqa
ImportError: No module named 'StringIO'

似乎 lib django-storages==1.1.8 尚不支持 Python3,这就是我收到该错误的原因。

我的问题是:我该如何解决这个问题?有没有类似的库来替换 django-storages?

我正在使用 django 1.7.1 和 Python3。

最佳答案

我刚刚用这个新的 repo 解决了我自己的问题:

https://github.com/jschneier/django-storages-redux/issues/6

这个线程使用这个新的 django-storages 有一个完整的解决方案

关于django - python 3中的S3BotoStorage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27178443/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com