【问题标题】:Divio Live server not serving the static files when DEBUG=False当 DEBUG=False 时,Divio Live 服务器不提供静态文件
【发布时间】:2018-11-02 11:16:07
【问题描述】:

我在 Divio Cloud 中运行一个网站。我的测试服务器可以正常提供静态文件,但我的 Live 服务器提供 404。当我在 Live 服务器上将 DEBUG 切换为 True 时,它​​开始正常提供静态文件。

当 Live 服务器启动时,它会在日志中显示:

[uwsgi-static] added mapping for /static/ => /app/static_collected

难道不应该注意正确地提供静态文件吗?

--编辑-- 更多信息。我实际上没有任何“正常”的静态文件。我使用 {% static %} 添加了一个静态文件,它正在工作!使用 django-sass-processor 和 django-compressor 收集不工作的文件。我在settings.py中有:

STATICFILES_FINDERS.extend([
    'compressor.finders.CompressorFinder',
    ])

这不应该只影响收集文件的时间吗?

【问题讨论】:

  • 你打电话给python manage.py collectstatic了吗?
  • 是的,它会自动调用 collectstatic 并且静态文件在 'static_collected' 目录中(我通过 SSH 连接到服务器来检查它们)
  • 实际上(不知道我是怎么搞砸的)文件不在“static_collected”目录中。显然这与 django-sass-processor 未处理 collectstatic 中的 scss 文件有关。

标签: django divio


【解决方案1】:

我认为问题很可能在于您使用的是 Django Compressor。使用 Django Compressor 有多种不同的方式。

在其文档中,请参阅Offline Compression。这是您在 Divio Cloud 上工作所需要的。

【讨论】:

  • 是的,它是压缩机。抱歉,我没有在这里发布我的发现。
【解决方案2】:

供将来参考:

在 Divio 环境中,要让基于压缩器的处理器(在本例中为 django-sass-processor)工作,请在 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

【讨论】:

    猜你喜欢
    • 2019-06-01
    • 2020-10-27
    • 2019-12-02
    • 2012-11-27
    • 2018-08-24
    • 2016-11-26
    • 1970-01-01
    • 2015-09-12
    • 2017-10-10
    相关资源
    最近更新 更多