新氧网站头图怎么做的,网站网页,信息门户系统,十大牌子网参考B站视频#xff1a;https://www.bilibili.com/video/BV1v7411M7us/
目录
第一讲 什么是 flask 修饰器、路由规则 flask 变量规则#xff0c;灵活传参数据类型#xff1a;str、int、float#xff08;正浮点数#xff0c;传int会报错#xff09;、path、uuid app.…参考B站视频https://www.bilibili.com/video/BV1v7411M7us/
目录
第一讲 什么是 flask 修饰器、路由规则 flask 变量规则灵活传参数据类型str、int、float正浮点数传int会报错、path、uuid app.run(host‘0.0.0.0’) 中设置 host‘0.0.0.0’ 让所有可以访问到本机 ip 的都可以使用。
第一讲
### 安装 pip install flask
第一讲1. 什么是 flask2. 修饰器、路由规则3. flask 变量规则灵活传参数据类型str、int、float正浮点数传int会报错、path、uuid4. app.run(host0.0.0.0) 中设置 host0.0.0.0 让所有可以访问到本机 ip 的都可以使用。
from flask import Flaskapp Flask(__name__)### 装饰器以下一行内容为使用装饰器来处理路由
app.route(/lyj) ### 路由即 网址端口号 的 / 之后添加对应的内容才能够访问以下对应的程序
def hello_world():return hello world.################# 路由规则
### 体验 127.0.0.15000/ 的 / 之后使用不同的内容
app.route(/hey) ### 路由即 网址端口号 的 / 之后添加对应的内容才能够访问以下对应的程序
def hey_music():return hey 永杰.### 灵活传参 str
app.route(/get_str/temp_str) ### temp_name 灵活传参的时候默认为 字符串
def get_str(temp_str):return get_str {} .format( temp_str temp_str )############# flask 变脸规则
### 灵活传参数据类型str、int、float正浮点数、path、uuid
app.route(/get_int/int:temp_num) ### 参数为 int 类型数据
def get_int(temp_num):return get_int {} .format( temp_num temp_num )### 参数为 float 类型正浮点数数据。 500 不行500.0 就可以
app.route(/get_float/float:temp_float)
def get_float(temp_float):return get_float {} .format( temp_float temp_float )app.route(/get_path/path:temp_path) ### 参数为 path 类型数据, 类似于接收字符串
def get_path(temp_path):return get_path {} .format( temp_path )### 通过此行内容进行执行程序
app.run(host0.0.0.0) ### host0.0.0.0 表示任何主机都可以访问不加的话 只有本机能够访问