Пример #1
0
async def init(loop):

    await orm.create_pool(loop=loop,
                          host="localhost",
                          port=3306,
                          user="******",
                          password="******",
                          db="my_blog")

    app = web.Application(
        loop=loop,
        middlewares=[logger_factory, auth_factory, response_factory])

    # 设置模板为jiaja2, 并以时间为过滤器
    init_jinja2(app, filters=dict(datetime=datetime_filter))

    # 注册所有url处理函数
    add_routes(app, "handlers")

    # 将当前目录下的static目录添加到app目录
    add_static(app)

    srv = await loop.create_server(app.make_handler(), '127.0.0.1', 5000)
    logging.info("server run at http://localhost:5000")
    return srv
Пример #2
0
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, 'handler');
    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;
Пример #3
0
async def init(loop):
	await 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 = 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, host='127.0.0.1', port=3306, user='******', password='******', db='online_learning')
    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', 9100)
    logging.info('server started at http://127.0.0.1:9100...')
    return srv
Пример #5
0
Файл: app.py Проект: smsn/pyweb
async def init(loop):
    await orm.create_pool(user=db['user'], password=db['password'], db=db['db'], loop=loop)
    app = web.Application(loop=loop, middlewares=[logger_factory, request_factory, response_factory])
    add_routes(app, 'handlers')
    add_static(app)
    init_jinja2(app, filters=dict(datetime_filter=datetime_filter))
    # 参数 app.make_handler() 返回一个可调用对象。下面是源码里的代码,定义了__call__,返回一个请求处理函数
    # def __call__(self) -> RequestHandler:
    #     return RequestHandler(self, loop=self._loop, **self._kwargs)
    server = await loop.create_server(app.make_handler(), host='0.0.0.0', port=8080)
    logging.info('Server started at http://0.0.0.0:8080 ...')
    return server
Пример #6
0
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)
    #127.0.0.1
    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
Пример #7
0
async def init(loop):
	await orm.create_pool(loop = loop,**config.configs.db)
	#创建应用对象
	app = web.Application(loop = loop,middlewares = [logger_factory,data_factory,response_factory,auth_factory])		#执行中间件
	#模板初始化
	init_jinja2(app,filters = dict(datetime = datetime_filter))
	#视图控制模块MVC将地址和页面关联
	add_routes(app,'handlers')
	add_static(app)
	#循环创建服务,有新的任务时,创建新的服务
	srv = await loop.create_server(app.make_handler(),'127.0.0.1',9000)
	#logging模块的参数,程序打印日志信息
	logging.info('server started at http://127.0.0.1:9000...')
	return srv
Пример #8
0
def init(loop):
    yield from orm.create_pool(loop=loop,
                               host="115.159.219.141",
                               port=3306,
                               user="******",
                               password="******",
                               db="webApp",
                               autocommit=True)
    app = web.Application(
        loop=loop,
        middlewares=[logger_factory, auth_factory, response_factory])
    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://115.159.219.141:80...')
    return srv
Пример #9
0
async def init(loop):
    await orm.create_pool(loop=loop,
                          host='127.0.0.1',
                          port=3306,
                          user='******',
                          password='******',
                          db='pure_blog')
    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
def init(loop):
    yield from orm.create_pool(loop=loop,
                               host='127.0.0.1',
                               port=3306,
                               user='******',
                               password='******',
                               db='online_learning')
    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', 9100)
    logging.info('server started at http://127.0.0.1:9100...')
    return srv
Пример #11
0
async def init(loop):
    rs = dict()
    await orm.create_pool(loop=loop, **configs.db)
    app = web.Application(loop=loop, middlewares=[
        logger_factory, auth_factory, response_factory
    ])
    app.on_shutdown.append(on_close)
    init_jinja2(app, filters=dict(datetime=datetime_filter, date=date_filter))
    add_routes(app, 'handlers')
    add_static(app)
    handler = app.make_handler()
    srv = await loop.create_server(app.make_handler(), '10.0.0.178', 9000)
    logging.info('server started at http://127.0.0.1:9000...')
    rs['app'] = app
    rs['srv'] = srv
    rs['handler'] = handler
    return rs
Пример #12
0
def init(loop):
    #创建数据库连接池,DB参数传配置文件里的DB
    yield from orm.create_pool(loop=loop, **configs.db)
    #middlewares设置两个中间处理函数
    #middlewares中的每个factory接受两个参数,app和handler(即middlewares中的下一个handler)
    #比如这里的logger_factory的handler参数其实就是response_factory()
    #middlewares的最后一个元素的Handler会通过routes查找到相应的,其实就是routes注册的handler
    app = web.Application(loop=loop, middlewares=[logger_factory, auth_factory, response_factory])
    # 初始化jinja2模板
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    # 添加请求的handlers,即各请求相对应的处理函数
    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
Пример #13
0
async def init(loop):
    await orm.create_pool(loop=loop, **configs.db)
    # await orm.create_pool(loop=loop, host='127.0.0.1', port=3306, user='******', password='******', db='pure_blog')
    '''
    # middlewares设置两个中间处理函数
    # middlewares中的每个factory接受两个参数,app 和 handler(即middlewares中得下一个handler)
    # 譬如这里logger_factory的handler参数其实就是response_factory()
    # middlewares的最后一个元素的Handler会通过routes查找到相应的,其实就是routes注册的对应handler
    '''
    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_routes(app, 'handlers_test')
    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
Пример #14
0
async def init():
    "Init Async Server"
    await orm.create_pool(host='127.0.0.1', port=3306, user='******', password='******', db='zero_blog')
    "Build web app"
    app = web.Application(middlewares=[
        logger_factory, response_factory
    ])

    # 添加jinja2模板
    init_jinja2(app)
    # 添加路由
    add_routes(app, 'handlers')

    runner = web.AppRunner(app)
    await runner.setup()
    site = web.TCPSite(runner, '127.0.0.1', 9000)
    logging.info('server started at http: //127.0.0.1:9000...')
    await site.start()
Пример #15
0
def init(loop):
    # 创建数据库连接池,db参数传配置文件里的配置db
    yield from orm.create_pool(loop=loop, **configs.db)
    # middlewares设置两个中间处理函数
    # middlewares中的每个factory接受两个参数,app 和 handler(即middlewares中得下一个handler)
    # 譬如这里logger_factory的handler参数其实就是response_factory()
    # middlewares的最后一个元素的Handler会通过routes查找到相应的,其实就是routes注册的对应handler
    app = web.Application(
        loop=loop,
        middlewares=[logger_factory, auth_factory, response_factory])
    # 初始化jinja2模板
    init_jinja2(app, filters=dict(datetime=datetime_filter))
    # 添加请求的handlers,即各请求相对应的处理函数
    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