0

I currently have a flask project deployed on IIS 11 using FastCGI and I was wondering if there is a way for me to print to the web console within the flask app.

1 Answer 1

1

Depends on when you need to print the message to the console. If it's live messaging like notifications / updates as they happen you'd need a websocket that creates an event on the Flask side that is picked up by Websockets on the javascript side that calls a console.log()

If it's a 1 time message once the page loads, just feed the message to the render_template() funciton:

render_template('index.html', message=message) 

You will then have that available in the template and then you can console.log(message) from the client side

Sign up to request clarification or add additional context in comments.

6 Comments

Good idea I will try this out. I was thinking something similar with the live messages and the websockets, I have done something similar in the past.
However, would it be possible to feed the python runtime errors to the console using the websocket method?
@ryan_thomp Im thinking a custom event for errors. On javascript side "socketio.on('error', function(data){console.log(data)})". On flask side have your try/except blocks emit a message on the except: "except Exception as e: socketio.emit('error', {'error': e})"
I did what you said however I see nothing within the developer console. Would you like me to make an edit to my main post to see what I did wrong
@ryan_thomp that works! I'll take a look once changed
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.