Static files are not loaded in Django

后端 未结 2 1242
醉梦人生
醉梦人生 2021-01-27 03:30

I\'m trying to follow these instructions to enable static files in my Django project. I have

STATIC_URL = \'/static/\'

in my settings.py file.

2条回答
  •  青春惊慌失措
    2021-01-27 04:12

    In settings.py include this:

    import os
    settings_dir = os.path.dirname(__file__)
    PROJECT_ROOT = os.path.abspath(os.path.dirname(settings_dir))
    
    STATICFILES_DIRS = (
        os.path.join(PROJECT_ROOT, 'static/mysite/'),
    )
    

    And in your urls.py include these lines at the end:

    from django.conf.urls.static import static
    from django.contrib.staticfiles.urls import staticfiles_urlpatterns
    urlpatterns += staticfiles_urlpatterns()
    

    Hope it helps.

提交回复
热议问题