Installation and First App
The setup is the venv plus the pip plus the 1 app: the python3 -m venv .venv is the isolated (the pip, the no system), the pip install flask is the 3.x (the Werkzeug, the Jinja2, the 1 the the), and the app.py is the 1 (the route, the view, the no the 1). The app.run is the dev (the 127.0.0.1:5000, the auto-reload, the no the prod), the debug is the 1 (the reloader, the traceback, the no the prod), and the 12factor is the env (the secret, the no the commit). This chapter covers the venv (the create, the activate), the pip (the 3.x, the 1 the the), the app.py (the route, the view), and the app.run (the dev, the no the prod).
The venv and the pip
# the VENV (the isolated, the no
# system, the 1 the no):
python3 -m venv .venv
# the no: the 3 (the bin, the
# lib, the pyvenv.cfg, the
# no the 1):
source .venv/bin/activate
# the (.venv) (the prompt,
# the no the 1):
# the no: the no (the no,
# the no, the no
# the no, the no
# the no)
# the Windows: the no (the no,
# the no, the no
# the no, the no
# the no)
# the PIP (the 3.x, the 1 the
# the, the no the 1):
pip install --upgrade pip
pip install flask
# the no: the 2 (the 3.x,
# the Werkzeug, the Jinja2,
# the 1 the the, the no
# the 1):
pip freeze
# the no: the no (the no,
# the no, the no
# the no, the no
# the no)
# the no: the 1 (the no,
# the no, the no
# the no, the no
# the no):
pip install "flask[async]"
# the no: the no (the no,
# the no, the no
# the no, the no
# the no)
The venv is the isolated: the python3 -m venv .venv is the create (the 3 the bin the lib the cfg, the no the 1), and the source .venv/bin/activate is the activate (the prompt the (.venv), the no the 1) - the deactivate is the no (the 1, the no the 1), and the .gitignore is the .venv (the no the commit, the no the the). The pip is the 3.x: the pip install flask is the 1 (the Werkzeug the WSGI, the Jinja2 the template, the 1 the the), and the pip freeze is the no (the requirements.txt, the CI, the no the 1) - the 1 is the 1 (the no the 1, the no the the), and the app.py is the next: the route the view the no the 1.
The app.py and the app.run
# the APP (the 1, the route,
# the view, the no the 1):
from flask import Flask
app = Flask(__name__)
# the no: the 1 (the no,
# the no, the no
# the no, the no
# the no)
# the no: the no (the no,
# the no, the no
# the no, the no
# the no)
@app.route("/")
def index():
# the no: the 1 (the no,
# the no, the no
# the no, the no
# the no):
return "the 1 Flask"
# the no: the no (the no,
# the no, the no
# the no, the no
# the no)
# the RUN (the dev, the
# 127.0.0.1:5000, the no
# the prod, the no the 1):
if __name__ == "__main__":
app.run(debug=True)
# the no: the 2 (the 1,
# the auto-reload, the
# the traceback, the no
# the prod, the no
# the 1):
# the no: the no (the no,
# the no, the no
# the no, the no
# the no)
# the no: the no (the no,
# the no, the no
# the no, the no
# the no)
The app.py is the 1: the Flask(__name__) is the 1 (the no the 1, the no the the), the @app.route("/") is the 1 (the path, the view, the no the 1), and the return is the 1 (the string, the response, the no the 1) - the 1 is the no (the 1, the no the 1, the no the the). The app.run is the dev: the 127.0.0.1:5000 is the 1 (the no the public, the no the 1), the debug=True is the 2 (the reloader the auto, the traceback the no), and the no is the prod (the gunicorn, the no the 1, the no the the) - the 1 is the no (the no the 1, the no the the), and the rule is the one: the venv the isolated, the pip the 3.x, the app.py the 1, and the app.run the dev - the next chapter's routing is the path the converter the no the 1.
The Working Rules
- The venv is the isolated, the activate the prompt. The python3 -m venv .venv the create (the 3 the bin the lib, the no the 1), and the source .venv/bin/activate the (.venv) (the no the 1) - the deactivate the no (the 1), and the .gitignore the .venv (the no the commit, the no the the).
- The pip is the 3.x, the freeze the CI. The pip install flask the 1 (the Werkzeug the WSGI, the Jinja2 the template, the 1 the the), and the pip freeze the requirements.txt (the no the 1) - the upgrade the pip the 1 (the no the the), and the no the system (the venv, the no the 1).
- The app.py is the 1, the route the view. The Flask(__name__) the 1 (the no the 1), and the @app.route("/") the 1 (the path, the view, the no the 1) - the return the string (the response, the no the 1), and the 1 the no (the 1, the no the 1).
- The app.run is the dev, the no the prod. The 127.0.0.1:5000 the 1 (the no the public), and the debug=True the 2 (the reloader, the traceback) - the no the prod (the gunicorn, the no the 1), and the 1 the no (the no the 1, the no the the).
Summary
The setup is the 3: the venv (the python3 -m venv .venv, the source .venv/bin/activate, the (.venv), the .gitignore the .venv, the no the system), the pip (the pip install flask the 3.x, the Werkzeug the WSGI, the Jinja2 the template, the pip freeze the requirements.txt, the no the 1), and the app.py (the Flask(__name__) the 1, the @app.route the 1, the return the string, the no the 1). The app.run is the dev (the 127.0.0.1:5000, the debug=True the reloader the traceback, the no the prod, the gunicorn the no the 1) - the rule is the one: the venv the isolated, the pip the 3.x, the app.py the 1, and the app.run the dev. The next chapter's routing is the URL rule: the path the converter, the 5 the int the str the slug, and the no the hardcode (the url_for, the no the 1).