zoukankan      html  css  js  c++  java
  • flask-蓝图

    蓝图作用

    相当于一个功能模块,能做到即插即用

    蓝图运用示例1:

    简单项目示例

     account.py

    #!/usr/bin/env python
    # -*- coding:utf-8 -*-
    from flask import Blueprint
    from flask import render_template
    from flask import request
    
    account = Blueprint('acc', __name__)
    
    
    @account.route('/login.html', methods=['GET', "POST"])
    def login():
        return render_template('login.html')

    blog.py

    #!/usr/bin/env python
    # -*- coding:utf-8 -*-
    from flask import Blueprint,url_for
    
    blog = Blueprint('blog', __name__)
    
    @blog.before_request
    def a():
        print("wo我是blog 的请求扩展")
    
    @blog.route("/index")
    def index():
        print(url_for("acc.login"))
        return "ok"

    user.py

    #!/usr/bin/env python
    # -*- coding:utf-8 -*-
    from flask import Blueprint
    
    user = Blueprint('user', __name__)

    __init__.py

    #!/usr/bin/env python
    # -*- coding:utf-8 -*-
    from flask import Flask
    
    app = Flask(__name__,template_folder='templates',static_folder='statics',static_url_path='/static')
    
    @app.before_request
    def a():
        print("我是app里面的befor_request")
    
    from .views.account import account
    from .views.blog import blog
    from .views.user import user
    
    app.register_blueprint(account)
    app.register_blueprint(blog)
    app.register_blueprint(user)

    run.py

    from pro_flask import app
    
    if __name__ == '__main__':
        app.run()

    复杂项目:

     admin/__init__.py

    from flask import Blueprint
    
    admin = Blueprint(
        'admin',
        __name__,
        template_folder='templates',
        static_folder='static'
    )
    from . import views
    View Code

    admin/views.py

    from . import admin
    
    
    @admin.route('/index')
    def index():
        return 'Admin.Index'
    View Code

    web/__init__.py

    from flask import Blueprint
    
    web = Blueprint(
        'web',
        __name__,
        template_folder='templates',
        static_folder='static'
    )
    from . import views
    View Code

    web/views.py

    from . import web
    
    @web.route('/index')
    def index():
        return 'Web.Index'
    View Code

    __init__.py

    #!/usr/bin/env python
    # -*- coding:utf-8 -*-
    from flask import Flask
    from .admin import admin
    from .web import web
    
    app = Flask(__name__)
    app.debug = True
    
    app.register_blueprint(admin, url_prefix='/admin')
    app.register_blueprint(web)
    View Code

    run.py

    from pro_flask import app
    
    if __name__ == '__main__':
        app.run()
    View Code
  • 相关阅读:
    做一个:网页请求数据库数据 流程
    开始一个Django项目的简单方法
    Django模板系统
    Python Django 中的STATIC_URL 设置和使用解析
    Django框架(一)-Django初识
    bootstrap
    jQuery
    js(jquery)鼠标移入移出事件时,出现闪烁、隐藏显示隐藏显示不停切换的情况
    PHPCMS快速建站系列之网站迁移(本地到服务器,服务器迁移,更换域名等)
    PHPCMS快速建站系列之在线留言
  • 原文地址:https://www.cnblogs.com/xiaowangba9494/p/11863005.html
Copyright © 2011-2022 走看看