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
