views:

144

answers:

1

Hello, in my settings.py I have the following:

PROJECT_DIR = os.path.dirname(os.path.realpath(__file__))
MEDIA_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

+2  A: 

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.

Tomasz Zielinski
Thanks Tomasz, that did it. I actually found this thread on Google which discusses a similar problem: http://groups.google.com/group/django-users/browse_thread/thread/0f50284640b855d3?pli=1I think I get it now.
PythonUser