Django中CSS加载background url('')问题
 
在django中, 默认CSS中如果有 background url('images/a.jpg') 这类的属性,会被django当成URL来解析
这样会造成找不到该文件的问题。
 
所以为了解决这个问题,首先需要配置setting.py, 配置STATICFILES_DIRS
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)
然后把需要引用的文件放入static目录

 

然后在html文件夹中,开头加入
{% load staticfiles %}
 
在需要引用图片的时候,把以前的写法
background url('images/a.jpg')
或
background='images/a.jpg'

  

改成
{% static "images/a.jpg" %}
 
即可
 
 
 
 

相关文章:

  • 2022-01-02
  • 2021-07-26
  • 2021-09-22
  • 2022-02-20
  • 2022-12-23
  • 2021-12-19
  • 2021-10-05
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-24
  • 2022-12-23
  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
  • 2021-05-30
相关资源
相似解决方案