美文网首页
python Flask 01

python Flask 01

作者: robertzhai | 来源:发表于2023-05-31 07:54 被阅读0次

What is Flask

  • Flask is a Python web “microframework.” One of the main selling points is that it is very quick to set up with minimal overhead. The Flask documentation has a web application example that’s under 10 lines of code and in a single script. Of course, in practice, it’s highly unlikely you’ll be writing a web application this small.

quick start

  • python -V

Python 3.10.10

from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello_world():
    return "<p>Hello, Flask!</p>"
  • flask --app main run --debug
  • visit http://127.0.0.1:5000/

cli layout

v1
helloworld/

├── .gitignore
├── helloworld.py
├── LICENSE
├── README.md
├── requirements.txt
├── setup.py
└── tests.py

v2
helloworld/

├── helloworld/
│ ├── init.py
│ ├── helloworld.py
│ └── helpers.py

├── tests/
│ ├── helloworld_tests.py
│ └── helpers_tests.py

├── .gitignore
├── LICENSE
├── README.md
├── requirements.txt
└── setup.py

v2
helloworld/

├── bin/

├── docs/
│ ├── hello.md
│ └── world.md

├── helloworld/
│ ├── init.py
│ ├── runner.py
│ ├── hello/
│ │ ├── init.py
│ │ ├── hello.py
│ │ └── helpers.py
│ │
│ └── world/
│ ├── init.py
│ ├── helpers.py
│ └── world.py

├── data/
│ ├── input.csv
│ └── output.xlsx

├── tests/
│ ├── hello
│ │ ├── helpers_tests.py
│ │ └── hello_tests.py
│ │
│ └── world/
│ ├── helpers_tests.py
│ └── world_tests.py

├── .gitignore
├── LICENSE
└── README.md

Web Application Layouts

flaskr/

├── flaskr/
│ ├── _init.py
│ ├── db.py
│ ├── schema.sql
│ ├── auth.py
│ ├── blog.py
│ ├── templates/
│ │ ├── base.html
│ │ ├── auth/
│ │ │ ├── login.html
│ │ │ └── register.html
│ │ │
│ │ └── blog/
│ │ ├── create.html
│ │ ├── index.html
│ │ └── update.html
│ │
│ └── static/
│ └── style.css

├── tests/
│ ├── conftest.py
│ ├── data.sql
│ ├── test_factory.py
│ ├── test_db.py
│ ├── test_auth.py
│ └── test_blog.py

├── venv/

├── .gitignore
├── setup.py
└── MANIFEST.in

flask-boilerplate

导出环境依赖

  • pip freeze >requirements.txt

blueprints

  • The basic concept of blueprints is that they record operations to execute when registered on an application. Flask associates view functions with blueprints when dispatching requests and generating URLs from one endpoint to another.

flask web demo

image.png
image.png
  • layout


    image.png
  • code

https://gitee.com/home_robertzhai/python_flask

ref

相关文章

网友评论

      本文标题:python Flask 01

      本文链接:https://www.haomeiwen.com/subject/eldosdtx.html