Skip to content

Instantly share code, notes, and snippets.

@aalaap
Created February 5, 2019 11:04
Show Gist options
  • Save aalaap/4a1edfeaf2b6bccf5d401a0503fc77c6 to your computer and use it in GitHub Desktop.
Save aalaap/4a1edfeaf2b6bccf5d401a0503fc77c6 to your computer and use it in GitHub Desktop.
Run a Flask app in production or development/debug from the command line
"""
Run a Flask app in production or development/debug from the command line
If you wish to run a Flask app with Python instead of the `flask run` command,
this code provides an easier way to decide if you want to run it in production
or debug mode.
Usage:
python flaskserver.py dev # runs with debug set to True
python flaskserver.py # production mode
"""
import sys
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello, world!"
if __name__ == '__main__':
is_debug = False
if len(sys.argv) > 1 and sys.argv[1] == 'dev':
is_debug = True
app.run(debug=is_debug)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment