在CSS,Django中使用静态图片 [英] use static image in css, django

查看:50
本文介绍了在CSS,Django中使用静态图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以加载CSS文件,该文件存储在静态文件夹中.但是,当我尝试在CSS文件中设置背景图片时.我失败了.

I can load CSS files, which is stored in static folder. However, when I try to set background image in the CSS file. I failed.

我在CSS中使用了 URL({{STATIC_URL}} images/img01.jpg),但没有加载图像.

I used URL({{ STATIC_URL }}images/img01.jpg) in css, but it didn't load the image.

推荐答案

您应始终在CSS中使用相对路径.例如. url(../images/img01.jpg) url(images/img01.jpg),具体取决于CSS文件的位置.

You should always use relative paths in your css. Eg. url(../images/img01.jpg) or url(images/img01.jpg) depending on the location of your css file.

模板渲染引擎未处理静态文件,因此您不能使用上下文变量或任何其他django模板化语法元素.您应该将静态文件视为按原样"提供的文件,而无需任何中间python或其他处理.

Static files are not processed by the template rendering engine, therefore you cannot use context variables or any other django templating syntactic elements. You should think your static files as files being served "as is", with no intermediate python or other processing.

这篇关于在CSS,Django中使用静态图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆