in Education by
I'm using Flask with HTML and CSS. When this is possible: image What do I have to write here to address the same image? .bgimg-1 { background-image: url('https://i.ytimg.com/vi/J9QOB6hSI-c/maxresdefault.jpg'); } The solution should look similar to this: .bgimg-1 { background-image: url('{{ url_for('static', filename='images/planets.jpeg' ) }}'); } Thank you. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You can't use Jinja directly in the CSS file since you normally don't render it as a template, but there is 3 alternate way to achieve your need: Method 1 Use correct relative path in your CSS file: background: url("/static/images/bg.jpg") no-repeat 0px 0px; Method 2 Put your background line into the template: background: url("{{ url_for('static',filename='images/bg.jpg') }}") no-repeat 0px 0px; Method 3 Define a CSS variable in your template: :root { --background-url: {{ url_for('static', filename='images/bg.jpg') }} } Then use it in your CSS file: background: url("var(--background-url)") no-repeat 0px 0px;

Related questions

0 votes
    I'm using Flask with HTML and CSS. When this is possible: What do I have to write here to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 12, 2022 in Education by JackTerrance
0 votes
    I want to upload the file pdf to the folder but a file is not saved to a folder. I already read the ... .run(debug=True)``` Select the correct answer from above options...
asked Jan 19, 2022 in Education by JackTerrance
0 votes
    Apologies if this question is answered elsewhere on StackOverflow, I did my best to search for an answer ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    I am looking for the best way to send large Numpy arrays (composed mainly of images) via Flask. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 13, 2022 in Education by JackTerrance
0 votes
    When I run my Dash app from the command line using export PYTHONPATH=./src/ && python ./src/pdv/ ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 6, 2022 in Education by JackTerrance
0 votes
    Nikunj has written the following style rule in the CSS file. H1(font-style=oblique; ) Is anything wrong with the ... yes, correct it. Select the correct answer from above options...
asked Dec 28, 2021 in Education by JackTerrance
0 votes
    What does the rel attribute of a variable have when the type of file is CSS? (a) css (b) ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 21, 2021 in Education by JackTerrance
0 votes
    I have a polygon feature in OpenLayers 5. It has some random id which I need to show at the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
0 votes
    I am trying to use Storybook v5.0 with my project and I am using React + Webpack4 + CSS Modules. ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    Explain the use of Bootstrap CSS class="navnav-list"....
asked Apr 4, 2021 in Education by JackTerrance
0 votes
    I want to right align alternate list elements and keep the other left making it a ZIG-ZAG list Something ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I have loaded a css file on server so I am having a URL with me. How can i load it in ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 5, 2022 in Education by JackTerrance
0 votes
    I want to display the label of an input inside its input, so that when I click the input, the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 3, 2022 in Education by JackTerrance
0 votes
    I've successfully floated labels above form input fields when focused, but I'm stumped on how to keep ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 1, 2022 in Education by JackTerrance
...