Python Forum
Flask, Display a picture outisde the static
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flask, Display a picture outisde the static
#2
This is the more normal way of doing this is to have a static folder for images,CSS,Js...ect
image_show\
  |-- app.py
    templates\
      |-- index.html
    static\
      images\
        |-- Joker.png
app.py
from flask import Flask, render_template, url_for

app = Flask(__name__)

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

@app.route('/about')
def about():
   pass

if __name__ == '__main__':
    app.run(debug=True)
index.html
<!DOCTYPE html>
<html lang="en">
 
<head>
  <title>About</title>
</head>
 
<body>
  This is our base template :) <BR>   
  <!-- Two ways -->
  <img src="static/images/Joker.png"> 
  <img src="{{ url_for('static', filename='images/Joker.png') }}"
</body>
 
</html>
Reply


Messages In This Thread
RE: Flask, Display a picture outisde the static - by snippsat - Aug-07-2020, 09:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question [Solved] Private static files SpongeB0B 1 1,115 Jul-16-2022, 05:36 AM
Last Post: SpongeB0B
  SHow image in a static link of Django pycada 3 2,626 Mar-04-2020, 01:50 AM
Last Post: pycada
  display multiple sensors on webpage python flask jinja pascale 6 5,368 Jan-29-2019, 10:10 AM
Last Post: pascale
  flask requests display data from api on webpage with javacript pascale 0 2,819 Oct-25-2018, 08:30 PM
Last Post: pascale
  Django loading static files Dutchpy 7 24,104 Oct-13-2017, 10:25 AM
Last Post: hbknjr

Forum Jump:

User Panel Messages

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