gunicorn + 夹层:找不到静态文件

gunicorn + mezzanine : static files are not found

我默认安装了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

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

谢谢 沫沫

对我来说还可以,谢谢!

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

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

If you still need to server static locally (e.g. for testing without debug) you can run devserver in insecure mode: manage.py runserver --insecure

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

in urls.py, add this:

from django.contrib.staticfiles.urls import staticfiles_urlpatterns

# ... the rest of your URLconf goes here ...

urlpatterns += staticfiles_urlpatterns()

更多信息here

干得好!