我的背景图片没有通过CSS文件加载。它通过前端加载:



<img class="top" src={% static "/store/img/store.jpg" %}>





在div内,但不包含:background:url('{{STATIC_URL}} / store / img / store.jpg');在css文件上。

我的路径是apps / store / static / store / img / store.jpg,所以很好。

HTML:



<div class="w3-display-container w3-content w3-wide" style="max-width:1600px;min-width:500px" id="home">
  <div class="w3-display-bottomleft w3-padding-large w3-opacity">
    <h1>SAN MIGUEL'S EXPORTA</h1>
  </div>
</div>





CSS:

#home{
    /* The image used */
background:  url('{{ STATIC_URL }}/store/img/store.jpg') no-repeat;

/* Full height */
height: 100%;

/* Create the parallax scrolling effect */
background-attachment: fixed;
background-position: center;
background-size: cover;


}

最佳答案

如果您使用的是django的标准模板引擎,则需要在引用静态文件之前先加载它们。在{% load static %}之前粘贴<img class="top" src={% static "/store/img/store.jpg" %}>

有关静态文件的更多帮助,请参见:
https://docs.djangoproject.com/pt-br/2.0/howto/static-files/#configuring-static-files

如果您愿意,随时向我询问更多问题!

关于python - Django背景图片CSS,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49909996/

10-16 19:36