Faculty of Engineering and Mathematical Sciences 
Not logged in (login)


This forum is provided to promote discussion amongst students enrolled in Agile Web Development (CITS3403).
RSS cloud
Jump to:

flask images in css

1 of 419 articles shown, currently no other people reading this forum.
From: Timothy F.
Date: Thu 7th May 2020, 1:18pm


"Aditya Gupta" <22*2*0*[email protected]*u*e*t*u*a*e*u*a*> wrote:

> Hi, my question is regarding how to import an image for CSS that is stored in an 'images' 
> folder which is nested in the 'static' folder.
> For example, I want the code in my CSS file to say:
> .intro {
>      background: url(...);
> }
> I have tried using both the normal path technique that is normally used in CSS 
> (/static/images/...) as well as tried using the jinja2 methods that are used in HTML {{ 
> url_for('static', filename='images/...') }}. However, none of my methods have worked so far 
> and I'm not sure why.
> Thanks

jinja is only interpretted server side, not by the browser, so url_for won't work.

css urls are interpreted relative to the location of the css file, so should probably be 
/images/... as the argument for url.

Related articles

flask images in css (both) RSS
├─ original   Wed 6th May 2020, 5:17pm, Aditya G.
└─ THIS   Thu 7th May 2020, 1:18pm, Timothy F.
This Page

Program written by: [email protected]
Feedback welcome
Last modified: 11:27am Sep 21 2020