0

I am creating my first website using Flask and I was wondering if it is possible to alter CSS files using jinja2 like html files... My frontend guy made all images to be in css and i can't figure out how to change them.

background: url(image link)

I want to fetch an image link from my mysql table, which stores a new image for every news post made, and display it there.

I found some solutions that use jinja2 but they are for local images stored on the same machine. Also i found a way to do it using html styling, but that makes the line way too long for html to look organized:

<div class="featured" style="background: linear-gradient(rgba(0, 0, 0, 0.1), black) border-box, url({{ article.thumbnail }}) no-repeat center center;">

Basically i need to fetch a link from MySQL table for each separate article that is written and display it accordingly...

What would be the best way to go here?

mpasd
  • 59
  • 9
  • You can point a url to a local file if it's in the static folder, as described [here](https://stackoverflow.com/questions/16351826/link-to-flask-static-files-with-url-for) and you can use jinja2 to add the link on the page when creating it as a [template](http://flask.pocoo.org/docs/1.0/tutorial/templates/). – tituszban Jul 08 '19 at 12:56
  • It is not a local file... Like i said, i need to fetch a link to the image which is stored in mysql database, like an imgur link or google images and just replace the link in url()... – mpasd Jul 08 '19 at 13:13
  • My bad. In that case just get the link from the database and insert it in the HTML. You can link to other images on the web. – tituszban Jul 08 '19 at 14:26
  • I did that, but adding styling makes that line of code way too big and just looks messy... Is that the only way to do this? – mpasd Jul 08 '19 at 14:29
  • 1
    You can add your styling in a css file and only insert the link on the html – tituszban Jul 08 '19 at 14:31

0 Answers0