0

My logo.jpg which is stored in /home/sally_venka/upload is not appearing.

This is my file index.html:

<body>
<html>    
<form method="GET" action="/show_index1">
<img src="{{ user_image }}" alt="User Image" width="200" height="85">
</body>
</html>

This is my file server.py:

UPLOAD_FOLDER1 = os.path.join('sally_venka', 'upload')
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER1 
@app.route('/show_index1',methods=['GET'])
def show_index1():
    full_filename = os.path.join(app.config['UPLOAD_FOLDER'], 'logo.jpg')
    render_template("index.html", user_image = full_filename)
    return redirect('/')
Helder Sepulveda
  • 15,500
  • 4
  • 29
  • 56
S P
  • 11
  • 1
  • 1
  • 2

2 Answers2

0

Maybe you could access the image with a static file path.

<img src="{{ url_for('static', filename = '/home/sally_venka/upload/logo.jpg') }}" alt="User Image" width="200" height="85">
Ashley van Laer
  • 91
  • 1
  • 2
  • 8
  • 1
    While true, this would defeat the purpose of a template because now you can't dynamically change the image displayed from the server side. This is functionally equivalent to just writing `` – Daniel W. May 01 '18 at 00:03
  • This link has the answer. https://stackoverflow.com/questions/20646822/how-to-serve-static-files-in-flask – Ashley van Laer May 01 '18 at 10:02
0

I see 2 problems here.

  1. Your HTML isn't formatted correctly. The <html> tag has to be on the first line.

  2. Paths. The way you create your file path by joining will result in the string: sally_venka/upload/logo.jpg. Your Browser will look at this path relative to wherever your index.html is located and will find nothing.

To solve this problem, try replacing

UPLOAD_FOLDER1 = os.path.join('sally_venka', 'upload')

with

UPLOAD_FOLDER1 = os.path.join(os.environ['HOME'], 'upload')

The resulting path (after appending the image filename) will be

/home/sally_venka/upload/logo.jpg

Which your browser will be able to find since it isn't a relative, but an absolute path to the file

Daniel W.
  • 623
  • 6
  • 14