【问题标题】:gunicorn + mezzanine : static files are not foundgunicorn + mezzanine:找不到静态文件
【发布时间】:2019-02-12 19:31:27
【问题描述】:

我默认安装了 Mezzanine CMS,我会尝试使用 gunicorn 服务

-- 使用python manage.py runserver仅在DEBUG = True

时提供所有静态文件

日志说:

... (DEBUG=False)
[07/Sep/2018 12:23:56] "GET /static/css/bootstrap.css HTTP/1.1" 301 0
[07/Sep/2018 12:23:57] "GET /static/css/bootstrap.css/ HTTP/1.1" 404 6165
...

-- 使用gunicorn helloworld.wsgi --bind 127.0.0.1:8000,找不到静态!

日志说:

$ gunicorn helloworld.wsgi --bind 127.0.0.1:8000

[2018-09-07 14:03:56 +0200] [15999] [INFO] Starting gunicorn 19.9.0
[2018-09-07 14:03:56 +0200] [15999] [INFO] Listening at: http://127.0.0.1:8000 (15999)
[2018-09-07 14:03:56 +0200] [15999] [INFO] Using worker: sync
[2018-09-07 14:03:56 +0200] [16017] [INFO] Booting worker with pid: 16017
Not Found: /static/css/bootstrap.css/
Not Found: /static/css/mezzanine.css/
Not Found: /static/css/bootstrap-theme.css/
Not Found: /static/mezzanine/js/jquery-1.8.3.min.js/
Not Found: /static/js/bootstrap.js/
Not Found: /static/js/bootstrap-extras.js/

请查看想要的 url:gunicorn 或 mezzanine(或其他?)在 url 末尾添加 / 字符。

我也做了这个命令python manage.py collectstatic没有效果:(

STATIC_ROOT 是正确的,我申请了https://docs.djangoproject.com/en/1.10/howto/static-files/#serving-static-files-during-development

您有提示或解决方案吗?恐怕我没有正确搜索!

谢谢 陌陌

【问题讨论】:

    标签: django python-3.x gunicorn django-staticfiles mezzanine


    【解决方案1】:

    我没问题,谢谢!

    正确的搜索为我找到了答案

    -- 内部服务器 DEBUG=False 不会提供静态文件,这是 webserver (nginx, apache) 的工作:Why does DEBUG=False setting make my django Static Files Access fail?

    如果您仍然需要在本地提供静态服务器(例如,用于无需调试的测试),您可以在不安全模式下运行 devserver: manage.py runserver --insecure

    -- 对于 gunicorn 网络服务器,我们需要在 urls.py 中手动添加静态:How to make Django serve static files with Gunicorn?

    urls.py 中添加:

    from django.contrib.staticfiles.urls import staticfiles_urlpatterns
    
    # ... the rest of your URLconf goes here ...
    
    urlpatterns += staticfiles_urlpatterns()
    

    更多信息here

    干得好!

    【讨论】:

      猜你喜欢
      • 2017-05-31
      • 1970-01-01
      • 2021-06-20
      • 2021-11-16
      • 2016-06-01
      • 2017-11-08
      • 2018-02-10
      • 2012-12-06
      相关资源
      最近更新 更多