Skip to content

Instantly share code, notes, and snippets.

@sgarciav
Last active March 26, 2023 15:01
Show Gist options
  • Save sgarciav/8a1cb14859291b15607e6f1c2b8c418b to your computer and use it in GitHub Desktop.
Save sgarciav/8a1cb14859291b15607e6f1c2b8c418b to your computer and use it in GitHub Desktop.
Collection of notes for Flask and Django development

Alternative method for displaying an image

This method relies on a static folder. Doesn't work when hosted on the web - which is why I needed to leverage the Google Cloud Storage.

@app.route('/display/<filename>')
def display_image(filename):
    return redirect(url_for('static', filename='processed_imgs/' + filename), code=301)

Syntax to use in html file if wanting to use the display_image function
{% if filenames %} 
<div> 
  <img src="{{ url_for('display_image', filename=filenames[0]) }}", style="float:left"> 
  <img src="{{ url_for('display_image', filename=filenames[1]) }}", style="float:left"> 
</div> 
{% endif %} 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment