I have referred the link here: More than one static path in local Flask instance and tried getting to display the image files in the browser tab, but couldn't do so. Unable to make out the mistake. stored_name is the physical filename of the file stored in the path specified by the app config constant variable: 'UPLOAD_FOLDER'. This folder is NOT in the static folder and its sub-folder path. I would like to increase storage capacity of files (maybe image files also), later by adding harddisk space, which is difficult if I use the static folder for storage. I don't want to override the static folder during app initialisation(which works)
Code snippets:
from flask import send_from_directory
@app.route('/api/v1.0/docs/<path:filename>', methods=["GET"])
def img_render(filename):
print 'Called here'
return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
@app.route('/api/v1.0/docs/<int:doc_id>',methods=["GET"])
def image_rendering(doc_id):
s = select([docs]).where(docs.c.id==doc_id)
rs = conn.execute(s).fetchone()
filename = str(rs[docs.c.stored_name])
return url_for('img_render', filename=filename)
Html template:
<!DOCTYPE html>
<html>
<body>
<img src="{{url_for('img_render', filename=filename) }}" />
</body>
</html>
The template is in the templates folder itself. If I override the original static folder during init of the application, I am able to get the images displayed in the browser, but I have to change my reference to the static folder for the application OR I will have to upload images into the static folder from the application, which I don't want to do. What is the mistake that it just displays the path of the image in the browser example:
/api/v1.0/docs/1_20160707_121214.jpg
and not the image itself? Where is the mistake in the code? Using flask v .0.11, linux 2.7.