【问题标题】:Heroku build django app doesn't create STATIC_ROOT dir if DEBUG=False. Why, what goes up in there?如果 DEBUG=False,Heroku 构建 django 应用程序不会创建 STATIC_ROOT 目录。为什么,里面发生了什么?
【发布时间】:2020-11-13 13:21:02
【问题描述】:

在 Heroku 上使用 DEBUG=True 的 Dajango (+channels/postgres/redis) 应用运行良好,没有错误,没有异常。如果 DEBUG=False 那么它实际上根本不起作用,error500。一些线索如何以这样的方式涉及 DEBUG 标志?谢谢。

Heroku 日志示例,DEBUG=True(工作正常):

GET path="/"

“GET/HTTP/1.1”302

“GET /accounts/login/?next=/HTTP/1.1”200

2020-07-23T16:14:24.496575+00:00 heroku[router]: at=info method=GET path="/" host=immense-escarpment-72885.herokuapp.com request_id=78bccd24-e86e-481f-995e-0aa31b2e440d fwd="68.14.159.220" dyno=web.1 connect=1ms service=117ms status=302 bytes=240 protocol=https
2020-07-23T16:14:24.495692+00:00 app[web.1]: 68.14.159.220:0 - "GET / HTTP/1.1" 302
2020-07-23T16:14:24.705467+00:00 app[web.1]: 68.14.159.220:0 - "GET /accounts/login/?next=/ HTTP/1.1" 200

登录页面显示,OK。

现在的问题:唯一的区别是 DEBUG=False:

GET path="/"

用户警告:没有目录:/app/pickupteaming/staticfiles/

“GET/HTTP/1.1”302

"GET /accounts/login/?next=/HTTP/1.1" 500

Heroku 日志示例详述如下:

2020-07-23T16:17:32.649059+00:00 heroku[router]: at=info method=GET path="/" host=immense-escarpment-72885.herokuapp.com request_id=22b8a783-04e8-4fda-a185-f0f39c69125e fwd="68.14.159.220" dyno=web.1 connect=0ms service=125ms status=302 bytes=240 protocol=https
2020-07-23T16:17:32.527579+00:00 app[web.1]: /app/.heroku/python/lib/python3.7/site-packages/whitenoise/base.py:116: UserWarning: No directory at: /app/pickupteaming/staticfiles/
2020-07-23T16:17:32.527606+00:00 app[web.1]: warnings.warn(u"No directory at: {}".format(root))
2020-07-23T16:17:32.643881+00:00 app[web.1]: 68.14.159.220:0 - "GET / HTTP/1.1" 302
2020-07-23T16:17:32.733941+00:00 app[web.1]: 68.14.159.220:0 - "GET /accounts/login/?next=/ HTTP/1.1" 500
2020-07-23T16:17:32.739475+00:00 heroku[router]: at=info method=GET path="/accounts/login/?next=/" host=immense-escarpment-72885.herokuapp.com request_id=991497fb-57f9-42f6-ae6b-c4a85dcdc79c fwd="68.14.159.220" dyno=web.1 connect=0ms service=60ms status=500 bytes=353 protocol=https

【问题讨论】:

    标签: django heroku build django-staticfiles


    【解决方案1】:

    当您设置 DEBUG=FALSE 时,您将设置为生产模式,而 Django 不会像在开发模式中那样提供静态文件,因为它效率低且不安全。您需要安装 WhiteNoise 并对您的 setting.py 文件进行一些调整。通过Mozilla查看这个优秀的指南

    【讨论】:

      猜你喜欢
      • 2020-08-31
      • 1970-01-01
      • 1970-01-01
      • 2013-04-19
      • 1970-01-01
      • 1970-01-01
      • 2021-08-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多