flask,示例及解释

1)

python 复制代码
from flask import Flask, render_template

app = Flask(__name__)


@app.route('/')
def index():
    return render_template('m1index.html')


@app.route('/get_type')
def get_type():
    return ["语文", "数学"]


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)

2)

from flask import Flask, render_template

表示从flask中引入相关包

3)

app = Flask(name)

定义对象

4)

@app.route('/')

def index():

return render_template('m1index.html')

表示默认的转发,即http://127.0.0.1:5000/

得到 的页面。

5)

@app.route('/get_type')

def get_type():

return "语文", "数学"

http://127.0.0.1:5000/get_type

可能会有乱码。

6)main函数

if name == 'main':

app.run(host='0.0.0.0', port=5000)

定义端口,及IP地址。

相关推荐
子兮曰3 天前
jev-ultrafast 深度解析:7 秒订机票的浏览器 Agent 是如何炼成的
前端·后端·agent
子兮曰3 天前
Jev 爆发一周:7 秒 Agent 背后的 System One 生态与三场争议
前端·后端·ai编程
默_笙3 天前
🍙 给每个请求过安检:FastAPI 是怎么把校验写进类型注解的
python
爱勇宝3 天前
ZCode 开源 24 小时:一份没有历史的账本,回答不了"有没有偷代码"
前端·后端·chatglm (智谱)
qq_426003963 天前
启动playwright录制codegen生成自动化测试脚本
python·自动化
虎头金猫3 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
胡写代码3 天前
别再前后端各写一套表单校验了
java·后端
长沙三为智能科技3 天前
家政小程序开发从0到上线:五阶段交付流程与验收清单
python
伞伞悦读3 天前
【第38期】Python 模块与包详解:import、from、模块搜索路径、包结构和 __init__
开发语言·python
大勇前进3 天前
原生 PHP 还是 Laravel?小项目到底要不要上框架
后端