liveBook · Manning

Flask run

As explained in The Well-Grounded Python Developer: How the pros use Python and Flask

flask run is the Flask command-line command that locates an application and starts its development server.

flask run locates a Flask application and starts its built-in development server. From the application directory, run the command in a terminal; the process stays active while it waits for HTTP requests. Stop it with Ctrl-C. section 6.4.2

from flask import Flask      #1
 
app = Flask(__name__)        #2
 
@app.route("/")              #3
def home():                  #4
    return "Hello World!"

A minimal Flask application defines an app instance, maps the root route, and returns a response that flask run can serve. section 6.4.2

A practical development setup includes:

  • Point FLASK_APP at the application, using shell-specific syntax such as FLASK_APP=app.py. section 6.5
  • Use the default local address, 127.0.0.1, and port 5000, unless different values are needed. section 6.4.2
  • Treat the built-in server as suitable for development and experimentation, not public production deployment; use a production-ready WSGI server such as Gunicorn or uWSGI instead. section 6.5

How The Well-Grounded Python Developer: How the pros use Python and Flask covers it

How deep it goes
Explains application selection, terminal behavior, default networking, and production limits without detailing server internals.
Examples
Uses a Hello World Flask app, FLASK_APP settings, localhost:5000, and terminal server output.
What it assumes
Assumes a Flask application, an installed chapter environment, and an active Python virtual environment.
What you can do after
Operate/configure a Flask development server by selecting an app, launching flask run, accessing localhost:5000, and stopping it.
How it connects
Connects Flask applications and environment variables with development servers, WSGI, Gunicorn, and uWSGI.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Python Developer: How the pros use Python and Flask. The section links point to the parts of the book it draws on.