flask 蓝图使用教程

本文介绍如何在Flask应用中使用Blueprint实现子模块路由,重点讲解`lantu_page`模块的`route_lantu`蓝图及其在`app.py`中的注册和URL前缀配置。通过实例展示了如何处理GET和POST请求,并演示了`hello`函数的调用。
摘要由CSDN通过智能技术生成

lantu.py

from flask import Blueprint

route_lantu = Blueprint( "lantu_page",__name__)

@route_lantu.route("/index",methods=['GET' , 'POST'])
def index():

    return "hello"
@route_lantu.route("/hello",methods=['GET' , 'POST'])
def hello():
    return "hello_lantu"

app.py

from flask import Flask
from lantu import route_lantu
from commen.libs.UrlManafer import UrlManager

app = Flask(__name__)

#把lantu.py引入,"/path"是你定义的路径,所有带/path的请求都会路由到lantu.py
app.register_blueprint( route_lantu,url_prefix = "/path")

@app.route("/hello" , methods=['GET' , 'POST'])
def hello():
    return "hello_lantu"

if __name__ == '__main__':
    app.run(host='0.0.0.0',debug = True)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值