def initialize_app(app, profile=False, config="webApp.config.AppConfig"): app.config.from_object(config) db.init_app(app) db.drop_all(app=app) db.create_all(app=app) redis_client.init_app(app=app) mongo_client.init_app(app=app) login_manager.init_app(app=app) csrf.init_app(app=app) cors.init_app(app=app) celery.init_app(app=app) if profile: from werkzeug.contrib.profiler import ProfilerMiddleware """ 请求性能测试参数说明: tottime : 在这个函数中所花费所有时间。 percall : 是 tottime 除以 ncalls 的结果。 cumtime : 花费在这个函数以及任何它调用的函数的时间。 percall : cumtime 除以 ncalls。 filename:lineno(function) : 函数名以及位置。 """ app.config['PROFILE'] = True app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30]) app.register_blueprint(rest_api_view) csrf.exempt(rest_api_view) # escape csrf protect if AppConfig.APP_SLOW_LOG: slow_logger_handler = generate_logger_handler( "app-slow", is_stream_handler=False, add_error_log=False, formatter=Formatter("%(asctime)s %(message)s")) app.slow_logger = create_logger("app-slow", handlers=slow_logger_handler) app.logger_name = "app" app.logger.setLevel(10) app.logger.handlers = generate_logger_handler("app") # handlers is a list
def init_db(): db.create_all() user = User(name='KoiCarrot', email='xxx', password='******') db.session.add(user) db.session.commit()
# -*- coding: utf-8 -*- from flask import Flask from extension import db from web import web SECRET_KEY = 'TeamBuilding' DEBUG = True SQLALCHEMY_DATABASE_URI = 'mysql://root:@localhost/TBuilding' app = Flask(__name__) app.config.from_object(__name__) db.init_app(app) app.register_blueprint(web, url_prefix='/web') with app.app_context(): db.create_all() #print "ok" if __name__ == '__main__': app.run()
def initial(): db.create_all()
def init_db(): db.create_all()
# -*- coding: utf-8 -*- from flask import Flask from extension import db from web import web SECRET_KEY = 'TeamBuilding' DEBUG=True SQLALCHEMY_DATABASE_URI = 'mysql://root:@localhost/TBuilding' app = Flask(__name__) app.config.from_object(__name__) db.init_app(app) app.register_blueprint(web, url_prefix='/web') with app.app_context(): db.create_all() #print "ok" if __name__ == '__main__': app.run()