Seung-Woo Lee
Seung-Woo Lee

Reputation: 251

How to disable flask app.run() 's default message

When running flask app, like

... 
if __name__ is "__main__":
    app.run(port=self.port)

...

There are some messages for running.

* Serving Flask app "__main__" (lazy loading)
* Environment: production
  WARNING: Do not use the development server in a production environment.
  Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

How I disable all these messages?

Upvotes: 7

Views: 8377

Answers (4)

alex devassy
alex devassy

Reputation: 587

I used to get below when I run flask app via python app.py

 * Serving Flask app 'app'
 * Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on all addresses (0.0.0.0)
 * Running on http://127.0.0.1:5000
Press CTRL+C to quit

added below code block in my app.py to remove the default flask message completely

import logging
log = logging.getLogger('werkzeug')
log.disabled = True
cli = sys.modules['flask.cli']
cli.show_server_banner = lambda *x: None

Upvotes: 2

synchalt
synchalt

Reputation: 19

Try this:

export WERKZEUG_RUN_MAIN=true

Upvotes: 1

Mike
Mike

Reputation: 1273

import flask.cli
flask.cli.show_server_banner = lambda *args: None

Upvotes: 0

user-asterix
user-asterix

Reputation: 936

To disable Flask from displaying warning banner messsage about using a development server in a production environment, add the 2 cli lines before running flask:

from flask import Flask
import sys

cli = sys.modules['flask.cli']
cli.show_server_banner = lambda *x: None

app = Flask(__name__)
app.run(host='0.0.0.0', port='80')

https://gist.github.com/jerblack/735b9953ba1ab6234abb43174210d356

Upvotes: 14

Related Questions