Flask中的管理

#模块管理
from flask import Blueprint

route_icc = Blueprint('icc',__name__)


@route_icc.route('/')
def index():
    return 'icc index'


@route_icc.route('/hello')
def hello():
    return 'icc hello'

app = Flask(__name__)
app.register_blueprint(route_icc,url_prefix='/icc')
#链接及版本管理

class UrlManager():

    @staticmethod
    def buildUrl(path):
        return path

    @staticmethod
    def buildStaticUrl(path):
        #版本号
        path = path+'?ver='+'202004162200'
        return UrlManager.buildUrl(path)


from common.libs.UrlManager import UrlManager

@app.route('/')
def hello_world():
    url = url_for('index')
    url_1 = UrlManager.buildUrl('/api')
    url_2 = UrlManager.buildStaticUrl('/css/bootstrap.css')
    return 'Hello World!' + url + url_1 + url_2
#日志管理
    msg = 'Hello World!' + url + url_1 + url_2
    app.logger.info(msg)
    app.logger.error(msg)
    app.logger.debug(msg)

#错误管理
@app.errorhandler(404)
def page_not_found(error):
    app.logger.error(error)
    return 'this page does not exist',404

 

posted @ 2020-04-16 22:39  Erick-LONG  阅读(246)  评论(0编辑  收藏  举报