idList = None if 'idList' in content_body_dict: idList = request.json.get('idList') return jsonify(allUnitCache) @app.route('/assist/list', methods=['POST']) def assistList(): if request.data: content_body_dict = json.loads(request.data) if 'unitId' in content_body_dict: unitId = request.json.get('unitId') print(unitId) unit = getUnit(unitId) asistDic = asistOptimize(unit) return jsonify(asistDic) @app.errorhandler(InvalidUsage) def error_handler(error): response = jsonify({'message': error.message, 'result': error.status_code}) return response, error.status_code if __name__ == '__main__': logs.init_app(app) allUnitCache = detailUnitList(1, -1, None).list app.debug = True #デバッグモード有効化 app.run(host='0.0.0.0', threaded=True) # どこからでもアクセス可能に
import models import routes import services import logs import logging def create_app(): app = Flask(__name__) models.init_app(app) routes.init_app(app) services.init_app(app) return app logs.init_app() # 初始化 logging.info(u'-----初始化项目-----') app = create_app() socketio = SocketIO(app) sockets.init_app(socketio) logging.info('--------------------') try: logging.info(u'------启动成功------') if isWindows(): socketio.run(app, host=server_info['host'], port=server_info['port']) else: socketio.run(app) except Exception as e: print e
from flask import Flask from flask.ext.sqlalchemy import SQLAlchemy from flask.ext.login import LoginManager import logs, errors app = Flask(__name__) app.config.from_object('config.BaseConfiguration') db = SQLAlchemy(app) login_manager = LoginManager() login_manager.login_view = 'login' login_manager.init_app(app) logs.init_app(app, remove_existing_handlers=True) errors.init_app(app) import views