我已经设置了我的Django项目,将静态和用户上传的文件存储到Amazon S3中。为了实现这一目标,我已经按照https://ashokfernandez.wordpress.com/2014/03/11/deploying-a-django-app-to-amazon-aws-with-nginx-gunicorn-git/发现的示例:
prod.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,这就是我收到错误的原因。
我的问题是:我该如何解决这个问题?是否有类似的lib来替换django-storages?
我使用的是django 1.7.1和Python3。
答案 0 :(得分:7)
我刚用这个新的回购解决了我自己的问题:
https://github.com/jschneier/django-storages-redux/issues/6
该线程使用这个新的django-storages
有一个完整的解决方案