How to make Django serve static files with Gunicorn?

前端 未结 6 1238
小鲜肉
小鲜肉 2020-11-30 20:27

I want to run my django project under gunicorn on localhost. I installed and integrated gunicorn. When I run:

python manage.py run_gunicorn

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-30 21:19

    Since Django 1.3 there is django/conf/urls/static.py that handle static files in the DEBUG mode:

    from django.conf import settings
    from django.conf.urls.static import static
    
    urlpatterns = [
        # ... the rest of your URLconf goes here ...
    ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    

    Read more https://docs.djangoproject.com/en/2.0/howto/static-files/#serving-static-files-during-development

提交回复
热议问题