django-pipeline和s3boto存储似乎并不合作 [英] django-pipeline and s3boto storage don't seem to work together
问题描述
我试图用s3boto来使用django-pipeline-1.1.27来压缩和过滤静态文件,然后将它们上传到s3桶。如果我只是使用:
PIPELINE_STORAGE ='pipeline.storage.PipelineFinderStorage'
/ pre>
然后它工作,我得到一个静态文件夹与我配置的漂亮的版本文件。一旦我切换到
PIPELINE_STORAGE ='storages.backends.s3boto.S3BotoStorage'
我得到
追溯(最近call last):
文件manage.py,第15行,在< module>
execute_manager(settings)
文件/my/virtual/env/lib/python2.7/site-packages/django/core/management/__init__.py,第438行,在execute_manager
utility.execute()
文件/my/virtual/env/lib/python2.7/site-packages/django/core/management/__init__.py,第379行,执行
自身.fetch_command(子命令).run_from_argv(self.argv)
文件/my/virtual/env/lib/python2.7/site-packages/django/core/management/base.py,第191行, run_from_argv
self.execute(* args,** options .__ dict__)
文件/my/virtual/env/lib/python2.7/site-packages/django/core/management/base.py ,行220,执行
output = self.handle(* args,** options)
文件/my/virtual/env/lib/python2.7/site-packages/pipeline/management /commands/synccompress.py,第39行,处理
packager.pack_stylesheets(包,sync = sync,force = force)
文件/my/virtual/env/lib/python2.7/ site-packages / pipeline / packager.py,第52行,pack_stylesheets
* * kwargs)
文件/my/virtual/env/lib/python2.7/site-packages/pipeline/packager.py,第60行,包
package ['output'],package ['路径])
文件/my/virtual/env/lib/python2.7/site-packages/pipeline/versioning/__init__.py,第45行,need_update
version = self .version(路径)
文件/my/virtual/env/lib/python2.7/site-packages/pipeline/versioning/__init__.py,第20行,版本
return getattr(self .versioner,'version')(路径)
文件/my/virtual/env/lib/python2.7/site-packages/pipeline/versioning/hash/__init__.py,第37行,版本
buf = self.concatenate(paths)
文件/my/virtual/env/lib/python2.7/site-packages/pipeline/versioning/hash/__init__.py,第27行,连续
返回'\\\
'.join(路径中的路径的[self.read_file(path)])
文件/my/virtual/env/lib/python2.7/site-packages/pipeline /versioning/hash/__init__.py,第31行,read_file
file = storage.open(path,'rb' )
文件/my/virtual/env/lib/python2.7/site-packages/django/core/files/storage.py,第33行,打开
file = self._open(名称,模式)
文件/my/virtual/env/lib/python2.7/site-packages/storages/backends/s3boto.py,第177行,_open
raise IOError('File不存在:%s'%name)
IOError:文件不存在:css / style.css
这是我的源文件之一。那么为什么当我切换到s3boto存储时,管道不再需要进行过滤器/连接/压缩步骤?
可能是我在做某事。这是其他配置,以帮助它:
INSTALLED_APPS =(
...
'pipeline' ,
'storages',
)
STATICFILES_FINDERS =(
'pipeline.finders.PipelineFinder',
'django.contrib.staticfiles.finders。 FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
STATIC_ROOT =/ some / path / outside / django_project / deploy_static
STATICFILES_DIRS =()#此网站中的所有静态都在应用程序
STATICFILES_STORAGE ='pipeline.storage.PipelineStorage'
PIPELINE_STORAGE ='storages.backends.s3boto.S3BotoStorage'
PIPELINE = True
PIPELINE_AUTO = True
PIPELINE_VERSION = True
PIPELINE_VERSION_PLACEHOLDER ='VERSION'
PIPELINE_VERSIONING ='pipeline.versioning.hash.SHA1Versioning'
PIPELINE_CSS = {
'standard':{
'source_filenames':(
'css / style.css' ,
...
),
'output_filename':'css / all-VERSION.css',
'extra_context':{
'media':'屏幕,投影',
},
}
}
我的网站在Django 1.3.1上。
我正在运行的命令是:
python manage.py synccompress --force
AWS凭据也在设置中,但是这是因为甚至没有达到这一点。
更新添加了评论中要求的完整堆栈和设置
更新根据图书馆作者的要求,我尝试升级到最新的测试版。到目前为止的观察:
- 我不知道如何获取版本压缩文件
- collectstatic离开我的压缩文件和原始文件
- 配置boto存储时仍然从django-pipeline中得到相同的错误:它想发送我的 source 文件到s3,但我甚至不能看到它在哪里上架我的资产。没有任何东西放在STATIC_ROOT中。
更新我创建了最简单的项目,适用于查找器存储和然后用S3Boto打破。我把它推送到github,并且包含了一个捕获栈跟踪。
https://github.com/estebistec/simple_pipeline
https://raw.github.com/estebistec/simple_pipeline/master/STACKTRACE
如果我被告知我正在做一些非常愚蠢的事情,我会感到欣喜若狂。这个应该都是正常的。
解决方案
django-pipeline 1.1.x
对于如何使用staticfiles有点愚蠢,它喜欢将所有内容都放在一个位置。
我建议你尝试django-pipeline 1.2
与最新的django-staticfiles
或django 1.4
。
使用这样的自定义:
STATICFILES_STORAGE ='your.app.S3PipelineStorage'
代码如下所示:
$ static code从staticfiles.storage导入CachedFilesMixin
from pipeline.storage import PipelineMixin
from storages.backends.s3boto import S3BotoStorage
class S3PipelineStorage(PipelineMixin,CachedFilesMixin,S3BotoStorage):
pass
您可以找到如何修复应用程序,但仍然存在编译文件的错误,除非您使用版本1.2c1: https://gist.github.com/1999564
I'm trying to use django-pipeline-1.1.27 with s3boto to compress and filter static files, and then upload them to an s3 bucket. If I just use:
PIPELINE_STORAGE = 'pipeline.storage.PipelineFinderStorage'
Then it works and I get a static folder with the nice versioned file that I configured. As soon as I switch to
PIPELINE_STORAGE = 'storages.backends.s3boto.S3BotoStorage'
I get
Traceback (most recent call last): File "manage.py", line 15, in <module> execute_manager(settings) File "/my/virtual/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager utility.execute() File "/my/virtual/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/my/virtual/env/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv self.execute(*args, **options.__dict__) File "/my/virtual/env/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute output = self.handle(*args, **options) File "/my/virtual/env/lib/python2.7/site-packages/pipeline/management/commands/synccompress.py", line 39, in handle packager.pack_stylesheets(package, sync=sync, force=force) File "/my/virtual/env/lib/python2.7/site-packages/pipeline/packager.py", line 52, in pack_stylesheets **kwargs) File "/my/virtual/env/lib/python2.7/site-packages/pipeline/packager.py", line 60, in pack package['output'], package['paths']) File "/my/virtual/env/lib/python2.7/site-packages/pipeline/versioning/__init__.py", line 45, in need_update version = self.version(paths) File "/my/virtual/env/lib/python2.7/site-packages/pipeline/versioning/__init__.py", line 20, in version return getattr(self.versioner, 'version')(paths) File "/my/virtual/env/lib/python2.7/site-packages/pipeline/versioning/hash/__init__.py", line 37, in version buf = self.concatenate(paths) File "/my/virtual/env/lib/python2.7/site-packages/pipeline/versioning/hash/__init__.py", line 27, in concatenate return '\n'.join([self.read_file(path) for path in paths]) File "/my/virtual/env/lib/python2.7/site-packages/pipeline/versioning/hash/__init__.py", line 31, in read_file file = storage.open(path, 'rb') File "/my/virtual/env/lib/python2.7/site-packages/django/core/files/storage.py", line 33, in open file = self._open(name, mode) File "/my/virtual/env/lib/python2.7/site-packages/storages/backends/s3boto.py", line 177, in _open raise IOError('File does not exist: %s' % name) IOError: File does not exist: css/style.css
which is one of my source files. So why does pipeline no longer want to do the filter/concatenate/compress steps when I switch to s3boto storage?
It may be that I'm doing something. Here is other config in case it helps:
INSTALLED_APPS = ( ... 'pipeline', 'storages', ) STATICFILES_FINDERS = ( 'pipeline.finders.PipelineFinder', 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', ) STATIC_ROOT = "/some/path/outside/django_project/deploy_static" STATICFILES_DIRS = () # All statics in this site are in apps STATICFILES_STORAGE = 'pipeline.storage.PipelineStorage' PIPELINE_STORAGE = 'storages.backends.s3boto.S3BotoStorage' PIPELINE = True PIPELINE_AUTO = True PIPELINE_VERSION = True PIPELINE_VERSION_PLACEHOLDER = 'VERSION' PIPELINE_VERSIONING = 'pipeline.versioning.hash.SHA1Versioning' PIPELINE_CSS = { 'standard': { 'source_filenames': ( 'css/style.css', ... ), 'output_filename': 'css/all-VERSION.css', 'extra_context': { 'media': 'screen,projection', }, } }
My site is on Django 1.3.1.
The command I'm running is:
python manage.py synccompress --force
The AWS creds are also in settings, but that's moot because it's not even getting to that point.
UPDATE Added full stack and settings requested in comments
UPDATE At the request of the library author, I tried upgrading to the latest beta. Observations from that so far:
- I don't know how to get versioned compressed files now
- collectstatic leaves me with the compressed files and the originals
- Still getting the same error from django-pipeline when boto storage is configured: it wants to send my source files to s3, but I can't even see where it's staging my assets. Nothing gets placed in STATIC_ROOT.
UPDATE I've created the simplest project that works for finder storage and then breaks with S3Boto. I've pushed it to github, and included a capture of the stacktrace.
https://github.com/estebistec/simple_pipeline https://raw.github.com/estebistec/simple_pipeline/master/STACKTRACE
I would be ecstatic if I could be told I'm doing some really dumb and this should all just work.
解决方案
django-pipeline 1.1.x
is a bit dumb about how you should use staticfiles, it prefers to have everything in one place. I suggest you to trydjango-pipeline 1.2
with latestdjango-staticfiles
ordjango 1.4
.Use a custom like this :
STATICFILES_STORAGE = 'your.app.S3PipelineStorage'
The code looks like this :
from staticfiles.storage import CachedFilesMixin from pipeline.storage import PipelineMixin from storages.backends.s3boto import S3BotoStorage class S3PipelineStorage(PipelineMixin, CachedFilesMixin, S3BotoStorage): pass
You can find how to fix your application, but there is still a bug with compiled files unless you use version 1.2c1 : https://gist.github.com/1999564
这篇关于django-pipeline和s3boto存储似乎并不合作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!