![](/img/trans.png)
[英]Whitenoise Not Working when DEBUG = FALSE - Django - Hosting Static Files
[英]Django whitenoise versioning not working
我與女服務員一起使用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>
然后按以下方式運行我的女服務員服務器:
服務生--port = 8080-致電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'
任何幫助或建議,高度贊賞!
DEBUG
設置為True
嗎? 僅當禁用調試模式時,staticfiles應用程序才會生成版本化的URL。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.