【问题标题】:Django-Compressor cannot find files when it's actually thereDjango-Compressor 无法找到实际存在的文件
【发布时间】:2012-10-08 02:40:58
【问题描述】:

我刚刚在我的项目中安装了 django-compressor,我收到以下错误消息。

TemplateSyntaxError at / Caught UncompressableFileError while 渲染:“js/jquery-1.7.2.min.js”在 COMPRESS_ROOT '/Users/taelimoh/Dropbox/gluwa-git/static' 或与 静态文件。

当我尝试压缩 css 文件时也会发生这种情况。

当然,文件在那里,当我不尝试使用 django-compressor 压缩它们时它工作正常。

下面是我的模板

...
    {% compress js %}
        <!--Javascripts-->
        <!--Libraries-->
        <script type="text/javascript" src="/static/js/jquery-1.7.2.min.js"></script>
    {% endcompress %}
...

这是我的 settings.py

COMPRESS_ENABLED = True

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'compressor.finders.CompressorFinder',
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'django.contrib.admindocs',
    'django.contrib.humanize',
    ##############################################
    'appconf',# required by django-compressor
    'versiontools',# required by django-compressor
    'compressor',#https://github.com/jezdez/django_compressor
    ...
)

我使用的是谷歌应用引擎,我的 django 版本是 1.3。 这个问题是在我的开发服务器上产生的。

【问题讨论】:

    标签: python django google-app-engine django-compressor


    【解决方案1】:

    这可能有点晚了,但文档指出,在您的 app.yaml 中配置了静态处理程序的任何文件都无法被应用程序读取。值得庆幸的是,还有一个开关可以让您的应用程序读取这些文件。你可以阅读它here。本质上,你会想要这样做

    handlers:
    - url: /static
    - static_dir: staticfiles
    - application_readable: true
    

    在您的app.yaml 中(注意application_readable)。我为此挣扎了一段时间,因为os.path.exists 总是失败。希望这会有所帮助。

    【讨论】:

    • 这听起来很有希望。我会检查并接受这一点。我最终没有使用压缩机,所以需要一些时间。非常感谢!
    • 别担心!希望对你有效。我试图使用 django-compressor 的离线缓存并遇到了您描述的问题,所以我猜您正在尝试做类似的事情?
    • 是的,我想我正在尝试同样的事情。
    【解决方案2】:

    GAE 应用对文件没有写入权限。如果 Django-compressor 试图将压缩文件写入文件系统,那将会失败。

    【讨论】:

    • 哎呀,你是对的,我的意思是 django-compressor。我不知道为什么其他版主拒绝了编辑。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-06-27
    • 1970-01-01
    • 1970-01-01
    • 2014-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多