Django: how do you serve media / stylesheets and link to them within templates

后端 未结 7 1689
心在旅途
心在旅途 2020-12-07 09:47

Variations of this question have been asked, but I\'m still unable to get my stylesheets to load correctly when my templates are rendered.

I\'m attempting to serve s

7条回答
  •  一个人的身影
    2020-12-07 09:58

    I just had to figure this out myself.

    settings.py:

    MEDIA_ROOT = 'C:/Server/Projects/project_name/static/'
    MEDIA_URL = '/static/'
    ADMIN_MEDIA_PREFIX = '/media/'
    

    urls.py:

    from django.conf import settings
    ...
    if settings.DEBUG:
        urlpatterns += patterns('',
            (r'^static/(?P.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
        )
    

    template file:

    
    

    With the file located here:

    "C:/Server/Projects/project_name/static/css/style.css"
    

提交回复
热议问题