简体   繁体   English

如何在 django 中添加背景图像作为 static 图像

[英]How to add a background imageas static image in django

please help me with this.请帮我解决一下这个。 I have an image slider.我有一张图片 slider。 it shoud add like this bellow..它应该像下面这样添加..

 <div class="slider-item" style="background-image: url('img/hero_2.jpg');"> <div class="container"> <div class="row slider-text align-items-center justify-content-center"> <div class="col-md-8 text-center col-sm-12 element-animate"> <h1>Delecious Food</h1> <p class="mb-5">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Commodi unde impedit, necessitatibus, soluta sit quam minima expedita atque corrupti reiciendis.</p> <p><a href="#" class="btn btn-white btn-outline-white">Get Started</a></p> </div> </div> </div> </div>

 Not working like these ways <div class="slider-item" style="background-image: url({%static'/img/hero_1.jpg'%});"> or <div class="slider-item" style="background-image: url{%static'/img/hero_1.jpg'%}"> I don't want to add like an img tag like this way " <img src="{% static '/img/hero_2.jpg' %}" />"
I am using Django latest version with python 3.0 all are latest version 我正在使用 Django 最新版本和 python 3.0 都是最新版本

Thank you谢谢

Update your settings.py file like given below and run command "python manage.py collectstatic"如下所示更新您的 settings.py 文件并运行命令“python manage.py collectstatic”在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM