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

help3403


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

flask images in css

2 of 419 articles shown, currently no other people reading this forum.
photo
From: Aditya G.
Date: Wed 6th May 2020, 5:17pm
Actions: 
        Login-to-reply

 

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

flask images in css

photo
From: Timothy F.
Date: Thu 7th May 2020, 1:18pm
Actions: 
        Login-to-reply

 

"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.
This Page


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