Esempio n. 1
0
def teardown_request(e):
    if e is not None:
        logger.error(Logger.dumps(t='exception', e=str(e)))
Esempio n. 2
0
def before_request():
    """如果HTTP Body为Json数据,需要设置Header
        Content-Type: application/json
    """
    logger.info(Logger.dumps(t='req'))
    request.on_json_loading_failed = on_json_loading_failed
Esempio n. 3
0
#-*- encoding: utf-8 -*-

from flask import Flask, request
app = Flask(__name__)
app.config.from_object('config')
app.config.from_envvar('FLASKY_API_CONFIG')

from flasky.lib.http.response import ApiError, make_api_resp, api_error_handler
from flasky.lib.http.request import on_json_loading_failed, get_or_400, get_arg_or_400, get_int_arg_or_400
from flasky.lib.http.session import set_user_session, get_user_id_or_401, need_session
"""初始化日志"""
from flasky.lib.log.logger import Logger, logger
Logger.init_logger(app.config['LOG_LEVEL'], app.config['LOG_FILE'])
"""导入Model"""
from flasky.model import db
db.init_app(app)
from flasky.model.flasky import User, Article, Label
"""设置错误处理
处理所有的HTTPException,输出对应的Json数据。因此,应用中则不能
    raise 400
    raise BadRequest
必须
    raise ApiError
    return make_api_resp()
"""


@app.errorhandler(ApiError)
def error_handler(error):
    return api_error_handler(error)
Esempio n. 4
0
def teardown_request(e):
    if e is not None:
        logger.error(Logger.dumps(t='exception', e=str(e)))
Esempio n. 5
0
def before_request():
    """如果HTTP Body为Json数据,需要设置Header
        Content-Type: application/json
    """
    logger.info(Logger.dumps(t='req'))
    request.on_json_loading_failed = on_json_loading_failed
Esempio n. 6
0
#-*- encoding: utf-8 -*-

from flask import Flask, request
app = Flask(__name__)
app.config.from_object('config')
app.config.from_envvar('FLASKY_API_CONFIG')

from flasky.lib.http.response import ApiError, make_api_resp, api_error_handler
from flasky.lib.http.request import on_json_loading_failed, get_or_400, get_arg_or_400, get_int_arg_or_400
from flasky.lib.http.session import set_user_session, get_user_id_or_401, need_session


"""初始化日志"""
from flasky.lib.log.logger import Logger, logger
Logger.init_logger(app.config['LOG_LEVEL'], app.config['LOG_FILE'])


"""导入Model"""
from flasky.model import db
db.init_app(app)
from flasky.model.flasky import User, Article, Label


"""设置错误处理
处理所有的HTTPException,输出对应的Json数据。因此,应用中则不能
    raise 400
    raise BadRequest
必须
    raise ApiError
    return make_api_resp()
"""