I would like to redirect sys.stdout
to a Jinja variable so that I can see it in the frontend (I'm using Flask server). How do I do this? Is there a better way to get the stdout to the HTML template?
This is what I have tried:
sys.stdout = jinja2.Template("<div id='console'>{{ console }}</div>")
But I get this error when using print
:
AttributeError: 'Template' object has no attribute 'write'
Exception ignored in: <Template memory:b4a2a9f0>
AttributeError: 'Template' object has no attribute 'flush'
I've seen posts like this, but I'm not sure how to implement it in my case. Any help is appreciated.