开发者

Django site_media relative url problem

开发者 https://www.devze.com 2023-01-01 11:50 出处:网络
in my settings.py I have the following: PROJECT_DIR = os.path.dirname(os.path.realpath(__file__)) M开发者_开发知识库EDIA_ROOT = os.path.join(PROJECT_DIR,\'templates\')

in my settings.py I have the following:

PROJECT_DIR = os.path.dirname(os.path.realpath(__file__))
M开发者_开发知识库EDIA_ROOT = os.path.join(PROJECT_DIR,'templates')
MEDIA_URL = '/templates/'

In urls.py I have (r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),

And my base.html has the following directive:

<link media="screen" href="site_media/bat/design/css/bat.css" type="text/css" rel="stylesheet" />

Upon first entry into the application (i.e. http://localhost) this stylesheet gets loaded just fine. However, on a subsequent http request (in urls.py it is (r'^assist/bat/', include('assist.bat.urls')), to another template this directive results in the following error:

The stylesheet http://localhost/assist/bat/site_media/bat/design/css/bat.css was not loaded because its MIME type, "text/html", is not "text/css."

As you can see, this css directive gets morphed into a relative url which is completely incorrect. If I remove /assist/bat from that url, then it works just fine. So how can I set up my app to not morph url's this way?

Thanks, Igor


Wild guess: href="site_media/bat/design/css/bat.css" should be href="/site_media/bat/design/css/bat.css", urls starting without slash in front of them are resolved relatively to the current url.

0

精彩评论

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