async def init(loop): #创建数据库连接池 await orm.create_pool(loop=loop, host='127.0.0.1', port=3306, user='******', password='******', db='webapp') #设置中间件(拦截器) app = web.Application(loop=loop, middlewares=[ logger_factory, response_factory, data_factory, auth_factory ]) #]) #初始化jinja2模板,并传入时间过滤器 init_jinja2(app, filters=dict(datetime=datetime_filter)) #下面这两个函数在webframe模块中,分别把handlers中的url处理函数注册到app中以及添加静态文件路径 add_routes(app, 'handlers') #handlers指的是handlers模块也就是handlers.py,这里不能加'.py' add_static(app) #异步监听访问请求 srv = await loop.create_server(app.make_handler(), '127.0.0.1', 9000) logging.info('server started at http://127.0.0.1:9000...') return srv
def init(loop): yield from orm.create_pool(loop=loop, **configs.db) app = web.Application(loop=loop, middlewares=[ logger_factory, auth_factory, response_factory ]) init_jinja2(app, filters=dict(datetime=datetime_filter)) add_routes(app, 'handlers') add_static(app) srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000) logging.info('server started at http://127.0.0.1:9000...') return srv
async def init(loop): await orm.create_pool(loop=loop, host=configs['db']['host'], port=configs['db']['port'], user=configs['db']['user'], password=configs['db']['password'], db=configs['db']['database']) app = web.Application(loop=loop, middlewares=[ logger_factory, response_factory, auth_factory ]) init_jinja2(app, filters=dict(datetime=datetime_filter)) add_routes(app, 'handlers') add_static(app) srv = await loop.create_server(app.make_handler(), configs['server']['host'], configs['server']['port']) logging.info('server started at http://%s:%s...'%(configs['server']['host'], configs['server']['port'])) return srv
async def init(loop): ' 服务器运行程序:创建web实例程序,该实例程序绑定路由和处理函数,运行服务器,监听端口请求,送到路由处理 ' await orm.create_pool(loop=loop, **config.configs.get('db')) #创建数据库连接池 app = web.Application( loop=loop, middlewares=[logger_factory, response_factory, auth_factory ]) #添加middleware,一个是请求日志记录的,另一个是对响应做处理 ,还有一个是cookie解析 add_routes(app, 'handlers') #将所有handlers添加进app add_static(app) init_jinja2(app, filters=dict(datetime=datetime_filter)) srv = await loop.create_server(app.make_handler(), '127.0.0.1', 9000) logging.info('Server started at http://127.0.0.1:9000') return srv
async def init(loop): # await orm.create_pool(loop=loop, host='127.0.0.1', port=3306, user='******', password='******', db='myblog') await orm.create_pool(loop=loop, **configs.db) app = web.Application(loop=loop, middlewares=[ logger_factory, auth_factory, data_factory, response_factory ]) init_jinja2(app, filters={'datetime': datetime_filter}) add_routes(app, 'handlers') add_static(app) srv = await loop.create_server(app.make_handler(), '127.0.0.1', 8000) logger.info('server started at http://127.0.0.1:8000...') return srv
async def init(): await orm.create_pool(loop=loop, **configs.db) app = web.Application( middlewares=[logger_factory, auth_factory, response_factory]) init_jinja2(app, filters=dict(datetime=datetime_filter)) add_routes(app, 'handlers') # add_routes(app, index) add_static(app) app_runner = web.AppRunner(app) # srv = await event_loop.create_server(app_runner.app.make_handler(), '127.0.0.1', 9000) await app_runner.setup() site = web.TCPSite(app_runner, '127.0.0.1', 9000) await site.start() logging.info('server started at http://127.0.0.1:9000...')
async def init(loop): await db.create_db_pool(loop=loop, host=configs['db']['host'], port=configs['db']['port'], user=configs['db']['user'], password=configs['db']['password'], database=configs['db']['database']) app = web.Application(loop=loop, middlewares=[logger_factory, response_factory]) add_static(app) add_routes(app, 'handlers') init_jinja2(app, filters=dict(datetime=datetime_filter)) srv = await loop.create_server(app.make_handler(), 'localhost', 9999) logging.info('server started at http://192.168.8.60:9999') return srv
async def init(loop): rs = dict() await myorm.create_pool(loop, **configs.database) app = web.Application(loop=loop, middlewares=[logger_factory, response_factory, auth_factory]) app.on_shutdown.append(on_close) init_jinja2(app, filters=dict(deltatime=deltatime_filter, date=date_filter)) add_routes(app, 'handlers') add_static(app) handler = app.make_handler() srv = await loop.create_server(handler, '127.0.0.1', 9000) logging.info('server started at http://127.0.0.1:9000...') rs['app'] = app rs['srv'] = srv rs['handler'] = handler return rs
async def init(loop): rs = dict() await orm.create_pool(loop, **configs.database) app = web.Application( loop=loop, middlewares=[logger_factory, logger_factory, auth_factory]) app.on_shutdown.append(on_close) init_jinja2(app, filters=dict(deltatime=deltatime_filter, date=date_filter)) add_routes(app, 'handlers') add_static(app) handler = app.make_handler() srv = await loop.create_server(handler, '127.0.0.1', 9000) logging.info('server started at http://127.0.0.1:9000...') rs['app'] = app rs['srv'] = srv rs['handler'] = handler return rs
async def init(loop): await orm.create_pool(loop=loop, host='127.0.0.1', port=3306, user="******", password="******", db="webapp") app = web.Application( loop=loop, middlewares=[logger_factory, auth_factory, response_factory]) init_jinja2(app, filters=dict(datetime=datetime_filter)) add_routes(app, 'handlers') add_static(app) srv = await loop.create_server(app.make_handler(), '127.0.0.1', 9000) logging.info('server started at http://127.0.0.1:9000...') return srv
async def init(loop): #' 服务器运行程序:创建web实例程序,该实例程序绑定路由和处理函数,运行服务器,监听端口请求,送到路由处理 ' # await orm.create_pool(loop=loop, **config.configs.db) # app = web.Application(loop=loop, middlewares=[logger_factory, response_factory]) # init_jinja2(app, filters=dict(datetime=datetime_filter)) # add_routes(app, 'handlers') # add_static(app) # srv = await loop.create_server(app.make_handler(), '127.0.0.1', 9000) # logging.info('Server started at http://127.0.0.1:9000') # return srv await orm.create_pool(loop=loop, **config.configs.db) app = web.Application(loop=loop, middlewares=[logger_factory, response_factory]) init_jinja2(app, filters=dict(datetime=datetime_filter)) add_routes(app, 'handlers') add_static(app) srv = await loop.create_server(app.make_handler(), '127.0.0.1', 9000) logging.info('Server started at http://127.0.0.1:9000') return srv