开发者

I can't load the css files

I want to load some .css files to my Django project but I don't know why they aren't loaded. The css files are located at "/myproject/media/css".

settings.py:

import os.path
PROJECT_DIR = os.path.dir开发者_StackOverflowname(__file__)    
MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')

urls.py:

from django.conf import settings
...
    (r'^media/(?P<path>.*)$', 'django.views.static.serve',
     {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),

)

base.html:

<link rel="stylesheet" type="text/css" media="all" href="{{ MEDIA_ROOT }}css/myStyle.css" />


Just a shot in the dark but if you have media root set to /myproject/media and then you reference {{ MEDIA_ROOT}}css/mystyle, aren't you missing a slash in there? So you are requesting /myproject/mediacss/myStyle

I feel you on troubleshooting this though. A pain.


MEDIA_ROOT is the file path to the assets, not the URL. The URL is set in urls.py, and you've got it as /media/, so that's what you need to use in the HTML tag.


Specifically, you should be using MEDIA_URL in your templates rather than MEDIA_ROOT.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜