How to Print to stdout in Flask using Python
If you are trying to print() to the console/stdout in your Flask app, but nothing is happening, then you just need to flush your prints, as follows:
print('This will print', flush=True)
Flask buffers stdout by default, which means your print statements get held in memory and may never appear in the terminal. I wasted a good chunk of time thinking my debug prints weren’t executing when they were just sitting in the buffer.
For background, see Python.
You can also set the PYTHONUNBUFFERED=1 environment variable to disable buffering globally, which is what most Dockerfiles do. Another option is using app.logger.info() instead of print() — it goes through Flask’s logging system and shows up immediately with proper timestamps and log levels.