Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flask Issues
#8
You need a static folder where you place images.
A  demo.
Folder:
img_demo\
app.py
    templates\
    index.html
   static\
       images\
       back.jpg
app.py:
from flask import Flask, render_template

app = Flask(__name__, static_url_path='')

@app.route("/")
def bak_image():
    return render_template("index.html")

if __name__ == '__main__':
    app.run()
index.html:
<html>
  <body>
    <p>Does the Image Work?</p>
    <style type="text/css">
      body {          
          background: url("{{ url_for('static', filename='images/back.jpg') }}") 0 0 no-repeat;
        }        
    </style>  
  </body>
</html>
So this will load "back.jpg" as background image.
Now i have CSS in html file.
For bigger stuff always have CSS in separate file,
it in also places in static folder.
Eg.
static\
    css\
    style.ccs
    js\
    some_javascript_stuff.js
Reply


Messages In This Thread
Flask Issues - by iainstott - Oct-27-2016, 06:02 PM
RE: Flask Issues - by micseydel - Oct-27-2016, 06:58 PM
RE: Flask Issues - by iainstott - Oct-27-2016, 07:13 PM
RE: Flask Issues - by micseydel - Oct-27-2016, 07:26 PM
RE: Flask Issues - by iainstott - Oct-27-2016, 07:50 PM
RE: Flask Issues - by iainstott - Oct-28-2016, 11:54 AM
RE: Flask Issues - by iainstott - Oct-28-2016, 02:05 PM
RE: Flask Issues - by snippsat - Oct-28-2016, 02:52 PM
RE: Flask Issues - by iainstott - Oct-28-2016, 04:01 PM
RE: Flask Issues - by snippsat - Oct-28-2016, 05:17 PM
RE: Flask Issues - by iainstott - Oct-29-2016, 02:38 PM
RE: Flask Issues - by snippsat - Oct-29-2016, 04:09 PM
RE: Flask Issues - by iainstott - Oct-29-2016, 06:07 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  flask issues with app structuring sidk23396 1 1,792 Feb-12-2020, 11:41 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020