Django media URLs in CSS files

Where is your css file served from? This usually isn’t a problem as a common media structure such as:

media/
    images/
    css/
    js/

(or similar) allows for relative file paths for images, eg:

background: url('../images/foo.png');

If you’re not prepared to change your media folder structure to accommodate relative file paths, you may have no alternative but to overwrite css declarations from within the template, using a secondary css file when offline:

{% if DEBUG %}
    <link rel="stylesheet" href="https://stackoverflow.com/questions/1023888/{{ MEDIA_URL }}css/offline-mode.css" />
{% endif %}

Of course the first option is much tidier.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)