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地址。

相关推荐
小陈工1 小时前
Python Web开发入门(十七):Vue.js与Python后端集成——让前后端真正“握手言和“
开发语言·前端·javascript·数据库·vue.js·人工智能·python
大鸡腿同学5 小时前
【成长类】《只有偏执狂才能生存》读书笔记:程序员的偏执型成长地图
后端
0xDevNull5 小时前
MySQL数据冷热分离详解
后端·mysql
A__tao5 小时前
Elasticsearch Mapping 一键生成 Java 实体类(支持嵌套 + 自动过滤注释)
java·python·elasticsearch
研究点啥好呢5 小时前
Github热门项目推荐 | 创建你的像素风格!
c++·python·node.js·github·开源软件
AI袋鼠帝5 小时前
OpenClaw(龙虾)最强开源对手!Github 40K Star了,又一个爆火的Agent..
后端
迷藏4946 小时前
**发散创新:基于Rust实现的开源合规权限管理框架设计与实践**在现代软件架构中,**权限控制(RBAC)** 已成为保障
java·开发语言·python·rust·开源
明日清晨6 小时前
python扫码登录dy
开发语言·python
bazhange6 小时前
python如何像matlab一样使用向量化替代for循环
开发语言·python·matlab
人工干智能7 小时前
科普:python中你写的模块找不到了——`ModuleNotFoundError`
服务器·python