简体   繁体   English

使用Django 1.2.5中的staticfiles应用程序进行静态文件的S3存储可能吗?

[英]S3 storage of static files using staticfiles app in Django 1.2.5 possible?

I have a website running on Django 1.2.5 which doesn't include the staticfiles app. 我有一个运行在Django 1.2.5上的网站,它不包含staticfiles应用程序。 I have however installed the staticfiles app via pip: 然而,我通过pip安装了staticfiles应用程序:

sudo pip install django-staticfiles

I then added the staticfiles app to settings.py: 然后我将staticfiles应用程序添加到settings.py:

INSTALLED_APPS += (
    'staticfiles',

however when I restart the server a get a 502 Bad Gateway error and the following error in /var/log/uwsgi/app/my-site.log: 但是,当我重新启动服务器时,在/var/log/uwsgi/app/my-site.log中出现502 Bad Gateway错误和以下错误:

Traceback (most recent call last):
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 248, in __call__
  response = self.get_response(request)
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 141, in get_response
  return self.handle_uncaught_exception(request, resolver, sys.exc_info())
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 165, in handle_uncaught_exception
  return debug.technical_500_response(request, *exc_info)
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/views/debug.py", line 59, in technical_500_response
html = reporter.get_traceback_html()
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/views/debug.py", line 141, in get_traceback_html
  return t.render(c)
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/template/__init__.py", line 173, in render
  return self._render(context)
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/template/__init__.py", line 167, in _render
  return self.nodelist.render(context)
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/template/__init__.py", line 796, in render
bits.append(self.render_node(node, context))
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/template/__init__.py", line 809, in render_node
  return node.render(context)
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/template/__init__.py", line 844, in render
output = self.filter_expression.resolve(context)
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/template/__init__.py", line 579, in resolve
new_obj = func(obj, *arg_vals)
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/template/defaultfilters.py", line 682, in date
  return format(value, arg)
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/utils/dateformat.py", line 281, in format
  return df.format(format_string)
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/utils/dateformat.py", line 30, in format
pieces.append(force_unicode(getattr(self, piece)()))
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/utils/dateformat.py", line 187, in r
  return self.format('D, j M Y H:i:s O')
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/utils/dateformat.py", line 30, in format
pieces.append(force_unicode(getattr(self, piece)()))
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/utils/encoding.py", line 66, in force_unicode
s = unicode(s)
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/utils/functional.py", line 206, in __unicode_cast
  return self.__func(*self.__args, **self.__kw)
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 55, in ugettext
  return real_ugettext(message)
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/utils/functional.py", line 55, in _curried
  return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 36, in delayed_loader
  return getattr(trans, real_name)(*args, **kwargs)
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 276, in ugettext
  return do_translate(message, 'ugettext')
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 266, in do_translate
_default = translation(settings.LANGUAGE_CODE)
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 176, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
 File "/var/projects/my-site/env/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
ImportError: No module named staticfiles

However I can import staticfiles when I run the following command from my Virtualenv folder: 但是,当我从Virtualenv文件夹运行以下命令时,我可以导入静态文件:

$ python manage.py shell
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import staticfiles
>>>

Essentially, I am trying to move the static files to S3 according to this blog post: 基本上,我试图根据这篇博文将静态文件移动到S3:

https://www.caktusgroup.com/blog/2014/11/10/Using-Amazon-S3-to-store-your-Django-sites-static-and-media-files/ https://www.caktusgroup.com/blog/2014/11/10/Using-Amazon-S3-to-store-your-Django-sites-static-and-media-files/

Is it possible to use the staticfiles app in Django 1.2.5 or do I have to upgrade Django? 是否可以在Django 1.2.5中使用staticfiles应用程序,还是必须升级Django?

I would rather not upgrade Django because I am sure this will break many other parts of the site. 我宁愿不升级Django,因为我相信这会破坏网站的许多其他部分。

What other options are there? 还有哪些其他选择? I assume it would possible to use boto somehow instead? 我认为可以用某种方式使用boto吗?

django-storage is not compatible with Django 1.2.2, unfortunately. 遗憾的是, django-storage与Django 1.2.2不兼容。
According to https://github.com/jschneier/django-storages 根据https://github.com/jschneier/django-storages

This library is usually compatible with the currently supported versions of Django. 该库通常与当前支持的Django版本兼容。 Check the trove classifiers in setup.py to be sure. 检查setup.py中的trove分类器是否确定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 S3 上存储静态文件,但在本地存储 staticfiles.json 清单 - Store static files on S3 but staticfiles.json manifest locally 带有S3静态文件优化的Django - Django with S3 staticfiles optimization 尝试将 static 文件上传到 S3 时,Django 一直使用错误的存储后端 - Django keeps using wrong storage backend when trying to upload static files to S3 Django staticfiles Amazon S3的问题 - Issue with django staticfiles amazon S3 使用boto3和存储将django app的静态文件上传到s3 - uploading static files of django app to s3 with boto3 and storages django 应用程序使用 amazon aws s3 存储代替 DB? - django app using amazon aws s3 storage in stead of DB? 使用AWS S3 for django在heroku上提供静态文件? - Serve static files on heroku using AWS S3 for django? 如何在Django 1.4中使用django.contrib.staticfiles提供管理静态文件(使用一个Apache服务器)? - How to serve admin static files with django.contrib.staticfiles in Django 1.4 (using one Apache server)? Django 不加载静态文件 ValueError(“缺少 '%s' 的静态文件清单条目”% clean_name) - Django doesn't load static files ValueError(“Missing staticfiles manifest entry for '%s'” % clean_name) href静态文件Django STATIC_URL和STATICFILES_DIRS - href static files Django STATIC_URL and STATICFILES_DIRS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM