I am using Django 1.3 with built-in static app.
My static folder structure is like this:
static/
css/
main.css
img/
js/
So I tried to reference images under static/css/img/
folder from CSS like this:
background:url('img/btn_white.gif') repeat-x;
But the images don'e show up. When I inspect elements in Chrome, I found the image path to be http://localhost/mysite/static/css/main.css/img/btn_white.gif/
Which is very wierd since this relative path should have referenced static/css/
folder instead of main.css
. So I tried to change path to be url('../img/btn_white.gif')
, and it works in Chrome and Firefox but not in IE.
I am pretty sure this problem is related to Django, because in my pure HTML/CSS, this relative path works just fine. I also tried to put css in media folder and the problem is the same.
My settings related to static app:
in settings.py:
STATIC_ROOT = os.path.join(os.path.dirname(__file__),'static').replace('\\','/')
STATIC_URL = 'http://localhost/mysite/static/'
in urls.py:
(r'^static/(?P<path>.*)/$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
Related question: Is a relative path in a CSS file relative to the CSS file?