Я не очень хорошо знаю внутренний механизм генерации изображений библиотекой PIL, но могу предложить простой подход:
Предположим, у вас есть такая структура:
root/
static/
img/
templates/
index.html
your_script.py
your_script.py
from PIL import Image
from flask import Flask, render_template
import datetime
app = Flask(__name__)
@app.route("/")
def hello():
img = Image.new('RGB', (60, 30), color = 'red')
img.save('static/img/red.png')
templateData = {
'title' : 'HELLO!',
'image': 'red'
}
return render_template('index.html', **templateData)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=80, debug=True)
index. html
<!DOCTYPE html>
<head>
<title>{{title}}</title>
</head>
<body>
<h1>Hello, World!</h1>
<img src="{{url_for('static', filename='img/')}}{{image}}.png">
</body>
</html>