Python全栈开发腾讯官方认证《逻辑教育》

334 阅读1分钟

Flask框架

1. flask简介和rul和视图

1.1 虚拟环境

Download:Python全栈开发腾讯官方认证《逻辑教育》提娶码:xb2k

1、虚拟环境和系统环境(全局环境)的区别

2、虚拟环境的必要性

3、虚拟环境的安装步骤

1)首先我们添加一个系统环境变量 变量名:WORKON_HOME 路径:xxxxxx

2)pip install pipenv

3)进入到你的项目文件夹中 pipenv shellVcmL46679910

4)来到pycharm中设置虚拟环境 

image.png

1.2 flask介绍和第一个flask程序

from flask import Flask

# import config app = Flask(__name__) 

@app.route('/') # 路由

def hello_world(): return 'hello world!'

 if __name__ == '__main__': 

app.run(debug=True))

 1.3 设置debug模式

1.app.run(debug=True)

2.app.debug = True

3.app.config.update(DEBUG=True)

4.app.config['DEBUG'] = True 

1.4 配置文件

1.写死的方式: app.config(DEBUG = True)

2.app.config.update(

DEBUG = TrueSECRECT_KEY = xxxxx

3.创建一个config.py文件

1)import config

2)app.config.from_object(config)

3)app.config.from_object('config')

4)app.config.from_pyfile('config.py', silent=True)

 1.5 url和视图

1、函数和rul的映射关系

2、数据约束类型

1)string: 默认的数据类型,接受没有任何斜杠/的字符串。

image.png 2)int: 整形

3)float: 浮点型。VcmL46679910

4)path: 和string类似,但是可以传递斜杠/。

5)uuid: uuid类型的字符串。

6)any:可以指定多种路径

d87529e79459565a1bbc81897eabff6.png

3、/ 分隔符

4、? 分隔符