Flask newbie here, trying to show an image through Flask.
==============================================
~/server.py
==============================================
#!/usr/bin/env python3.6
import os
from flask import Flask, request, render_template, g, redirect, Response, send_from_directory
tmpl_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates')
print(tmpl_dir)
app = Flask(__name__, template_folder=tmpl_dir)
@app.route('/')
def index():
print(request.args)
return render_template("index.html")
if __name__ == "__main__":
app.run()
==============================================
~/templates/index.html:
==============================================
<!DOCTYPE html>
<html>
<body>
<h1>Text-to-Image Synthesis</h1>
<img src="/home/n/templates/tree.jpg" width="700" height="500">
</body>
</html>
Things I've tried:
- send_from_directory()
- render_template("index.html", **context)
- Literally copying the code from python flask display image on a html page
The image tree.jpg
is in the proper directory.