Django media URLs in CSS files

后端 未结 4 369
青春惊慌失措
青春惊慌失措 2021-02-02 07:12

In django templates, it\'s common to do the following:


How would you accomplish this in a

4条回答
  •  北荒
    北荒 (楼主)
    2021-02-02 07:45

    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 %}
        
    {% endif %}
    

    Of course the first option is much tidier.

提交回复
热议问题