【问题标题】:Django whitenoise versioning not workingDjango白噪声版本控制不起作用
【发布时间】:2016-02-05 09:35:34
【问题描述】:

我正在使用 whitenoise 和女服务员来提供我的静态文件,但我无法让它使用版本化的静态文件。例如,如果我有一个 foo.js,在我运行 collectstatic 之后,whitenoise 会在我的静态文件夹中创建以下文件:

foo.js
foo.js.gz
foo.10a400e06df8.js
foo.10a400e06df8.js.gz where 10a400e06df8 is the unique version code that whitenoise generated for me.

这是我的 wsgi.py 文件:

from django.core.wsgi import get_wsgi_application

# This is the default application
application = get_wsgi_application()

def white():
    # This is an alternative WSGI app that wraps static content
    from whitenoise.django import DjangoWhiteNoise
    white = get_wsgi_application()
    white = DjangoWhiteNoise(white)
    return white

这是我在模板中包含 foo.js 的方式:

{% load static from staticfiles %}
...
<script src="{% static "foo.js" %}" type="text/javascript"></script>

我按如下方式运行我的服务员服务器:

waitress-serve --port=8080 --call myapp.wsgi:white

当我加载我的页面时,我希望我会在我的浏览器中看到这个

 <script src="/static/foo.10a400e06df8.js" type="text/javascript"></script>

但我还是看到了

<script src="/static/foo.js" type="text/javascript"></script>

我错过了什么吗?在我的设置中,我确实有 STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

非常感谢任何帮助或建议!

【问题讨论】:

    标签: python django django-staticfiles waitress


    【解决方案1】:

    DEBUG 是否设置为 True? staticfiles 应用仅在禁用调试模式时生成版本化 URL。

    【讨论】:

      猜你喜欢
      • 2017-06-16
      • 2018-10-23
      • 1970-01-01
      • 2019-02-01
      • 2018-03-10
      • 1970-01-01
      • 2016-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多