Working on a flask project, I've integrated a visually appealing front-end design from codepen.io into my HTML template using BeautifulSoup. The design can be found here.
I have a list of images obtained through web scraping that I want to display in place of the existing image by utilizing jinja2.
It's worth noting that the images are embedded within the CSS.
.clash-card__image {
position: relative;
height: 230px;
margin-bottom: 35px;
border-top-left-radius: $border-radius-size;
border-top-right-radius: $border-radius-size;
}
.clash-card__image--barbarian {
background: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/195612/barbarian-bg.jpg");
img {
width: 400px;
position: absolute;
top: -65px;
left: -70px;
}
}
Although I have successfully displayed images in the body of the HTML template using jinja2, I am facing challenges when it comes to referencing images in the CSS as shown below:
{% for image, title in images_titles %}
.clash-card__image--barbarian {
background: url("{{images");
{% endfor %}
Despite attempting various iterations of the above code snippet, I haven't been able to get the images to display. However, I can successfully display the titles since they are located in the HTML part.
An additional hurdle is that the size of the image list may vary. I am seeking a solution where the cards automatically replicate without the need for manually inserting {{image}} references in each CSS definition.
My query is this: How can I effectively incorporate the jinja2 reference to the images stored in the list within the CSS?
Any advice on best practices and suggestions would also be greatly appreciated.