djangopython-3.xgunicorndjango-staticfilesmezzanine

gunicorn + mezzanine : static files are not found


I installed a Mezzanine CMS by default and I will try to serve by gunicorn

-- With python manage.py runserver, all static files are served only if DEBUG = True

Logs said:

... (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
...

-- With gunicorn helloworld.wsgi --bind 127.0.0.1:8000, no static found!

Logs said:

$ 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/

Please have a look to url wanted: gunicorn or mezzanine (or else?) add a / character in the end of url.

I did this command too python manage.py collectstatic with no effect :(

STATIC_ROOT is correct and I applied https://docs.djangoproject.com/en/1.10/howto/static-files/#serving-static-files-during-development

Do you have a tips or solution? I'm afraid I didn't search correctly!

Thanks Momo


Solution

  • It's Ok for me, thanks!

    A correct search found me the answers

    -- for internal server DEBUG=False will not serve static files, it's a job for webserver (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

    -- for gunicorn webserver, we need add static manually in 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()
    

    More info here

    well done!