欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

flask views文件转化成views包

程序员文章站 2024-02-03 22:27:10
...

views转化成包
flask views文件转化成views包
蓝图注册转移到App/views/init.py中:
App/views/init.py

from .first_blue import blue
from .second_blue import second

def init_view(app):
    app.register_blueprint(blue)
    app.register_blueprint(second)

App/views/first_blue.py

from flask import Blueprint, render_template

blue = Blueprint('blue', __name__)

@blue.route('/')
def index():
    return render_template('index.html',msg="睡觉")

App/views/second_blue.py

from flask import Blueprint

second = Blueprint('second', __name__)


@second.route('/hello/')
def hello():
    return "hello second"

views的路由注册在App/init.py中:

from flask import Flask

from App.views import init_view


def create_app():
    app = Flask(__name__)
    init_view(app=app)
    return app

相关标签: flask