feat: add flask.md cheatsheet (#222)

This commit is contained in:
kjch 2022-12-12 01:26:17 -05:00 committed by GitHub
parent 3964c0c301
commit 470ccb5311
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 2 deletions

View File

@ -24,6 +24,7 @@ Quick Reference
[C#](./docs/cs.md)<!--rehype:style=background: rgb(6 147 13);&class=contributing-->
[Django](./docs/djiango.md)<!--rehype:style=background: rgb(12 75 51);&class=contributing tag&data-lang=Python-->
[FFmpeg](./docs/ffmpeg.md)<!--rehype:style=background: rgb(0 193 9);&class=contributing-->
[Flask](./docs/flask.md)<!--rehype:style=background: rgb(210 168 255);&class=contributing tag&data-lang=Python-->
[Flutter](./docs/flutter.md)<!--rehype:style=background: rgb(150 220 254);&class=contributing tag&data-lang=Dart-->
[Gitlab CI/CD](./docs/gitlab-ci.md)<!--rehype:style=background: rgb(226 67 41);&class=contributing-->
[LaTeX](./docs/latex.md)<!--rehype:style=background: rgb(0 128 128);&class=contributing-->
@ -44,7 +45,8 @@ Quick Reference
[Dart](./docs/dart.md)<!--rehype:style=background: rgb(64 196 255);-->
[Docker](./docs/docker.md)<!--rehype:style=background: rgb(72 143 223);-->
[Dockerfile](./docs/dockerfile.md)<!--rehype:style=background: rgb(0 72 153);&class=tag&data-lang=Docker-->
[Django](./docs/djiango.md)<!--rehype:style=background: rgb(12 75 51);&class=contributing tag&data-lang=Python-->
[Django](./docs/djiango.md)<!--rehype:style=background: rgb(12 75 51);&class=contributing tag&data-lang=Python-->
[Flask](./docs/flask.md)<!--rehype:style=background: rgb(210 168 255);&class=contributing tag&data-lang=Python-->
[Flutter](./docs/flutter.md)<!--rehype:style=background: rgb(150 220 254);&class=contributing tag&data-lang=Dart-->
[Golang](./docs/golang.md)<!--rehype:style=background: rgb(39 160 193);-->
[GraphQL](./docs/graphql.md)<!--rehype:style=background: rgb(214 66 146);-->
@ -395,7 +397,7 @@ Quick Reference
[cms.im](https://quickref.cms.im/)<!--rehype:target=_blank-->
[nuomiphp.com](https://reference.tool.nuomiphp.com/)<!--rehype:target=_blank-->
[eryajf.net](https://ref.eryajf.net/)<!--rehype:target=_blank&class=contributing&data-info=👆每天自动同步-->
[kjchmc.cn](https://ref.kjchmc.cn/)<!--rehype:target=_blank&class=contributing&data-info=👆实时同步,自动切换国内外节点-->
[kjchmc.cn](https://ref.kjchmc.cn/)<!--rehype:target=_blank&class=contributing&data-info=👆实时同步,多线路-->
<!--rehype:class=home-card home-links-->
如果你有资源,可以很方便部署 web 版,这非常简单,只需要克隆 [gh-pages](https://github.com/jaywcjlove/reference/tree/gh-pages) 分支代码到你的静态服务就可以了,还可以使用 [docker](https://hub.docker.com/r/wcjiang/reference) 快捷部署 web 版。

8
assets/flask.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 7.2 KiB

55
docs/flask.md Normal file
View File

@ -0,0 +1,55 @@
Flask 备忘清单
===
本清单对 Flask 的入门进行了简要的概述,以及其常用示例。需要有 `HTML``Python` 基础。
入门
-----
### 相关链接
- [HTML](https://developer.mozilla.org/en-US/docs/Web/HTML) _(developer.mozilla.org)_
- [Python](https://www.python.org/) _(python.org)_
- [Flask](https://flask.palletsprojects.com/) _(flask.palletsprojects.com)_
- [Python 备忘清单](./python.md) _(kjchmc.cn)_
### Hello World
#### hello.py
```python
# 导入 Flask 类
from flask import Flask
# 创建应用实例
app = Flask(__name__) # 'Flask' 参数是 应用程序模块 或 包 的名称
# __name__是适用于大多数情况的便捷快捷方式
# 路由 (装饰器)
@app.route('/') # route()装饰器告诉 Flask 什么路径触发下面的功能
def hello():
return 'Hello World!' # 该函数返回我们想要在浏览器中显示的消息内容
# 默认类型 HTML, 因此字符串中的 HTML 将被浏览器渲染
# 启动服务
if __name__ == '__main__':
app.run()
```
### 运行 `hello.py` 程序
```shell
$ python hello.py
* Serving Flask app 'hello'
* Running on http://127.0.0.1:5000
* Press CTRL+C to quit
```
#### 或
```shell
$ flask --app hello run
* Serving Flask app 'hello'
* Running on http://127.0.0.1:5000
* Press CTRL+C to quit
```