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.

Revisions

  1. aalaap created this gist Feb 5, 2019.
    29 changes: 29 additions & 0 deletions flaskserver.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    """
    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)