Flask 的安装 | 珊瑚贝

Flask 是一个轻量级的 Web 服务程序,简单、易用、灵活,在本书中我们主要用它来做一些 API 服务,本节我们来了解下它的安装方式。

相关链接

pip 安装

推荐使用 pip 安装,命令如下:

1
pip3 install flask

运行完毕之后就可以完成安装。

验证安装

安装成功之后可以运行如下实例代码测试一下:

1
2
3
4
5
6
7
8
9
from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
return "Hello World!"

if __name__ == "__main__":
app.run()

直接运行代码,可以发现系统会在 5000 端口开启 Web 服务,控制台输出如下:

1
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

直接访问:http://127.0.0.1:5000/,可以观察到网页中呈现了 Hello World!,如图所示:

这样一个最简单的 Flask 程序就运行成功了。

来源:https://cuiqingcai.com/31038.html

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_11516.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?