当 DEBUG=False 时,Divio Live 服务器不提供静态文件
Divio Live server not serving the static files when DEBUG=False
我是运行 Divio Cloud 中的一个网站。我的测试服务器可以很好地提供静态文件,但我的实时服务器会出现 404。当我在实时服务器上将 DEBUG 切换为 True 时,它会开始很好地提供静态文件。
当 Live 服务器启动时,它在日志中有这样的内容:
[uwsgi-static] added mapping for /static/ => /app/static_collected
这不应该负责正确提供静态文件吗?
--编辑--
更多信息。我实际上没有任何 "normal" 静态文件。我使用 {% static %} 添加了一个静态文件,它正在工作!不工作的文件是用 django-sass-processor 和 django-compressor 收集的。我在 settings.py:
STATICFILES_FINDERS.extend([
'compressor.finders.CompressorFinder',
])
这不应该只影响收集文件的时间吗?
我认为问题很可能是因为您使用的是 Django Compressor。使用 Django Compressor 有多种不同的方式。
在其文档中,请参阅 Offline Compression。这就是它在 Divio Cloud 上运行所需要的。
供日后参考:
在 Divio 环境中,要使基于压缩器的处理器(在本例中为 django-sass-处理器)工作,请在 Dockerfile 的末尾添加以下内容:
RUN DJANGO_MODE=build python manage.py compilescss
# <STATIC>
RUN DJANGO_MODE=build python manage.py collectstatic --noinput
# </STATIC>
# Remove the css files in development environments (in Live they
# are already collected)
RUN DJANGO_MODE=build python manage.py compilescss --delete-files
我是运行 Divio Cloud 中的一个网站。我的测试服务器可以很好地提供静态文件,但我的实时服务器会出现 404。当我在实时服务器上将 DEBUG 切换为 True 时,它会开始很好地提供静态文件。
当 Live 服务器启动时,它在日志中有这样的内容:
[uwsgi-static] added mapping for /static/ => /app/static_collected
这不应该负责正确提供静态文件吗?
--编辑-- 更多信息。我实际上没有任何 "normal" 静态文件。我使用 {% static %} 添加了一个静态文件,它正在工作!不工作的文件是用 django-sass-processor 和 django-compressor 收集的。我在 settings.py:
STATICFILES_FINDERS.extend([
'compressor.finders.CompressorFinder',
])
这不应该只影响收集文件的时间吗?
我认为问题很可能是因为您使用的是 Django Compressor。使用 Django Compressor 有多种不同的方式。
在其文档中,请参阅 Offline Compression。这就是它在 Divio Cloud 上运行所需要的。
供日后参考:
在 Divio 环境中,要使基于压缩器的处理器(在本例中为 django-sass-处理器)工作,请在 Dockerfile 的末尾添加以下内容:
RUN DJANGO_MODE=build python manage.py compilescss
# <STATIC>
RUN DJANGO_MODE=build python manage.py collectstatic --noinput
# </STATIC>
# Remove the css files in development environments (in Live they
# are already collected)
RUN DJANGO_MODE=build python manage.py compilescss --delete-files