I am simply trying to display an image in html using flask. But I am unable to do so even though I've given the complete correct path of image.
I've followed this link
python flask display image on a html page
My samply.py
is
import os
from flask import Flask, flash, request, redirect, url_for, render_template
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
@app.route('/show_image')
def show_index():
full_filename = os.path.join(app.config['UPLOAD_FOLDER'], '2.jpg')
return render_template("layout.html", user_image = full_filename)
if __name__ == "__main__":
app.run(debug=True)
And my HTML code:
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
</head>
<body>
<img src="{{ user_image }}" alt="User Image">
</body>
</html>
I am getting output of
127.0.0.1 - - [09/Jun/2019 11:50:41] "GET /home/user/Documents/images/2.jpg HTTP/1.1" 404 -
When I follow this link /home/user/Documents/images/2.jpg
in my vscode, it's displaying the correct image; which means there's noting wrong with the path.