async def init(loop): # app=web.Application(loop=loop) # app.router.add_route('GET','/',index) # srv=await loop.create_server(app.make_handler(),'127.0.0.1',9000) # logging.info('server started at http://127.0.0.1:9000...') await orm.create_pool(loop=loop, host='localhost', port=3306, user='******', password='******', db='awesome') app = web.Application(loop=loop, middlewares=[ logger_factory, auth_factory, data_factory, response_factory ]) #... # init_jinja2(app, filters=dict(datetime=datetime_filter)) # add_routes(app, 'handlers') # add_static(app) # logging.info('#####################################') # logging.info(index.__dict__) init_jinja2(app, filters=dict(datetime=datetime_filter)) # add_route(app,index) add_routes(app, 'handlers') add_routes(app, 'handlers_blog') add_static(app) # app.router.add_route('GET','/',index) srv = await loop.create_server(app.make_handler(), '127.0.0.1', 9001) logging.info('server started at http://127.0.0.1:9001') return srv
async def app_init(event_loop): """ 网站初始化函数 :param event_loop: 事件循环对象 :return: 服务器对象 """ # 创建数据库连接池 await orm.create_pool( loop=event_loop, host='bdm240853593.my3w.com', user='******', password='******', db='bdm240853593_db') # 创建网站应用对象 # middlewares 接收一个列表,列表的元素就是拦截器函数 # aiohttp内部循环里以倒序分别将url处理函数用拦截器装饰一遍 # 最后再返回经过全部拦截器装饰过的函数, 这样最终调用url处理函数之前或之后就可以进行一些额外的处理 web_app = web.Application(loop=event_loop, middlewares=[logger_factory, auth_factory,response_factory]) # 初始化前端模板, 指定的过滤器函数可以在模板文件中使用 init_jinja2(web_app, filters=dict(datetime=datetime_filter)) # 添加路由函数 coreweb.add_routes(web_app, 'handlers.py') # 添加静态文件 coreweb.add_static(web_app) # 创建服务器 server = await event_loop.create_server(web_app.make_handler(), '127.0.0.1', 9000) logging.info('server started at http://127.0.0.1:9000...') return server
async def init(loop): # 设置数据库 await orm.create_pool(loop=loop, host='127.0.0.1', port=3306, user='******', password='******', db='thanos') # 创建web app,并设置拦截器middleware app = web.Application( loop=loop, middlewares=[ # 实现接口,链表式处理request,完成处理后回调request出去(通过handler) logger_factory, auth_factory, response_factory ]) # 初始化View模板 init_jinja2(app, filters=dict(datetime=datetime_filter)) # 自动将handlers模块中的函数注册为处理URL的函数(也是上面设置的各拦截器middlewares中最终调用的函数) add_routes(app, 'handlers') add_static(app) # 创建web 服务 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,user='******',password='******',db='awesome') 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 start at http://127.0.0.1:9000...') return srv
async def init(loop): await create_pool(loop=loop, **configs.db) app = web.Application(loop=loop, middlewares=[logger_factory, data_factory, auth_factory, response_factory]) init_jinja2(app, filter=dict(datetime=datetime_filter)) add_routes(app, 'handler') add_static(app) # app.router.add_route('GET', '/', index) srv = await loop.create_server(app.make_handler(), '127.0.0.1', 8080) logging.info('server started at http://127.0.0.1:8080...') return srv
async def init(loop): app = web.Application(loop=loop, middlewares=[logger_factory, response_factory]) init_jinja2(app) add_routes(app, 'handlers') add_static(app) srv = await loop.create_server(app.make_handler(), '127.0.0.1', 9091) logging.info('server started at http://127.0.0.1:9091...') return srv
async def init(loop): await orm.create_pool(loop=loop, host=host, port=data_port, user='******', password='******', database='awesome') 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) server = await loop.create_server(app.make_handler(), host, port) logging.info("server started at http://127.0.0.1:9001...") return server
def init(loop): yield from orm.create_pool(loop=loop, host='127.0.0.1', port=3306, user='******', passwd='py3_webapp', db='awesome') 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 = 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='123.56.1.161', port=3306, user='******', password='******', db='pythonweb') app = web.Application( loop=loop, middlewares=[logge_factory, auth_factory, response_factory]) init_jinja2(app, filters=dict(datetime=datetime_filter)) # add_route(app, handlers.index) add_routes(app, 'handlers') add_static(app) # srv = await loop.create_server(web.AppRunner(app), '127.0.0.1', 80) srv = await loop.create_server(app.make_handler(), '127.0.0.1', 80) logging.info('server started at http://127.0.0.1:80...') return srv
def init(loop): yield from orm.create_pool(loop=loop, host='127.0.0.1', port=3306, user='******', password='******', db='awesome') app = web.Application(loop=loop, middlewares=[ logger_factory, response_factory ]) # app.router.add_route('GET', '/', index) 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(): host = configs.db.host port = configs.db.port user = configs.db.user pw = configs.db.password db = configs.db.db await orm.create_pool(host=host, port=port, user=user, password=pw, db=db) app = web.Application( middlewares=[logger_factory, auth_factory, response_factory]) init_jinja2(app, filters=dict(datetime=datetime_filter)) add_routes(app, "handlers") add_static(app) return app
async def init(loop): app = web.Application(loop=loop, middlewares=[logger_factory, response_factory]) init_jinja2( app, filters=dict(datetime=datetime_filter), path=r"E:\python_workspace\awesome-python3-webapp\www\templates" ) #初始化Jinja2,这里值得注意是设置文件路径的path参数 add_routes(app, 'webframe_test_handler') 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): #app = web.Application(loop = loop, host = '127.0.0.1', port = 3306, user = '******', password = '******', database = 'awesome') logger.info(configs.database) yield from orm.create_pool(loop = loop, **configs.database) app = web.Application(loop = loop, middlewares = [ logger_factory, auth_factory, response_factory ]) init_jinja2(app, filters = dict(datetime = datetime_filter, ensure_http = ensure_http)) add_routes(app, 'handlers') add_static(app) #app.router.add_route('GET', '/', index) srv = yield from loop.create_server(app.make_handler(), 'localhost', 9000) logger.info('Server started at http://127.0.0.1:9000...') return srv
async def make_app(): # 创建数据库连接池 await orm.create_pool(host='localhost', port=3306, user='******', password='******', db='py3app') # middlewares 是一种拦截器,一个URL 在被某个函数处理之前,可以经过一系列middlewares 的处理 # middlewares 可以改变URL 的输入、输出,甚至可以决定不继续处理而直接返回 # middlewares 的用处是把通用的功能从每个URL 处理函数中拿出来,集中放到一个地方,比如logger_factory 可以记录URL 日志 app = web.Application(middlewares=[logger_factory, response_factory]) init_jinja2(app, filters=dict(datetime=datetime_filter)) add_routes(app, 'handlers') add_static(app) return app
async def init(loop): await orm.create_pool(loop, **configs['db']) app = web.Application( loop=loop, middlewares=[auth_factory, logger_factory, response_factory]) init_jinja2(app, filters=dict(datetime=datetime_filter), path=r"./templates") # 初始化Jinja2,这里值得注意是设置文件路径的path参数 coreweb.add_routes(app, 'handlers') coreweb.add_static(app) srv = await loop.create_server(app.make_handler(), '127.0.0.1', 9900) logging.info('server started at http://127.0.0.1:9900...') return srv
def init(loop): yield from myorm.create_pool(loop=loop, host='127.0.0.1', port=3306, user='******', passwd='123456', db='myblog') app = web.Application( loop=loop, middlewares=[logger_factory, response_factory, auth_factory]) init_jinja2(app, filters=dict(datetime=datetime_filter)) coreweb.add_routes(app, 'handlers') coreweb.add_static(app) srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 9000) logging.info('server start at 127.0.0.1:9000.....') return srv
async def init(loop): await orm.create_pool(loop=loop, host='localhost', port=3306, user='******', password='******', db='awesome') app = web.Application( loop=loop, middlewares=[logger_factory, response_factory, auth_factory]) init_jinja2(app, filters=dict(datetime=datatime_filter)) add_routes(app, 'handlers') add_static(app) srv = await loop.create_server(app.make_handler(), 'localhost', 9000) logging.info('sever started at http://localhost:9000...') return srv
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(), '0.0.0.0', 8858) logging.info('server started at http://0.0.0.0:8858') return srv
async def init(loop): await orm.create_pool(loop=loop, **configs.db) # middleware是一种拦截器,一个URL在被某个函数处理前后,可以经过一系列的middleware的处理 # 调用过程是:url request -> middlewares -> RequestHandler -> (请求)handler(返回) -> RequestHandler -> middlewares -> url response app = web.Application( loop=loop, middlewares=[logger_factory, auth_factory, response_factory]) # 初始化jinja2模板组件,并且给模板添加filter,增加获取时间的功能 init_jinja2(app, filters=dict(datetime=datetime_filter)) # 'handlers'模块里定义的都是请求的处理函数(就是controls) add_routes(app, 'handlers') # 添加静态资源:/static/下的资源 add_static(app) srv = await loop.create_server(app.make_handler(), '127.0.0.1', 8888) logging.info('server started at http://127.0.0.1:8888...') return srv
async def init(loop): config_data = getConfig() db = config_data.get('blog_db') website = config_data.get('website') if(db is None): raise Exception('Please check your config...') await orm.create_pool(loop, **db) # (self, *, logger = web_logger, loop = None, router = None, handler_factory = RequestHandlerFactory, middlewares = (), debug = False) app = web.Application(loop=loop, middlewares = [loggerfactory, response_factory]) app['website_host'] = website.get('host') init_jinja2(app, filters = dict(datetime=datetime_filter)) add_routes(app, 'handlers') add_static(app) add_upload(app) srv = await loop.create_server(app.make_handler(), website.get('host'), website.get('port')) logging.info('Server started at http://%s:%s...' % (website.get('host'), website.get('port'))) return srv
async def init(loop): # logger.info(configs.database) # await orm.create_pool(loop=loop, **configs.database) app = web.Application(client_max_size=1024**2 * 5, loop=loop, middlewares=[ logger_factory, data_factory, auth_factory, response_factory ]) init_jinja2(app, filters=dict(datetime=datetime_filter, ensure_http=ensure_http)) add_routes(app, 'handlers') add_static(app) # app.router.add_route('GET', '/', index) srv = await loop.create_server(app.make_handler(), '0.0.0.0', 8030) logger.info('Server started at http://127.0.0.1:8030...') return srv
async def init(loop): await orm.create_pool(loop=loop, host='127.0.0.1', port=3306, user='******', password='******', db='awesome') app = web.Application( loop=loop, middlewares=[logger_factory, auth_factory, response_factory]) # 前端模板 init_jinja2(app, filters=dict(datetime=datetime_filter)) # URL 处理函数自动扫描注册 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): # app = web.Application(loop=loop) # app.router.add_route('GET', '/', Index) # 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 yield from orm.create_pool(loop=loop, host='127.0.0.1', port=3306, user='******', password='******', db='awesome') # 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="127.0.0.1", post=3306, user="******", password="******", db="univesre") app = web.Application(loop=loop, middlewares=[logger_factory, response_factory]) # 传进异步事件loop对象; init_jinja2(app, filters=dict(datetime=datetime_filter)) add_routes(app, 'handler') add_static(app) # app.router.add_route('GET', '/', index) # add_route方法: 调用index(), 对首页"/"进行响应; srv = await loop.create_server( app.make_handler(), '127.0.0.1', 9000 ) # 产生一个服务: 在127.0.0.1地址和9000端口上, 这应该都是托aiohttp模块福吧(对指定网址路径, 指定网络地址进行响应); logging.info( 'Server started at http://127.0.0.1:9000...') # 调试信息为INFO等级, 输出到终端..; return srv # 返回srv: 啥意思, 就是index()的返回了, 那个html label, 没错!;
async def init(loop): host = config.configs.get('db').get('host') port = config.configs.get('db').get('port') user = config.configs.get('db').get('user') password = config.configs.get('db').get('password') db = config.configs.get('db').get('db') await orm.create_pool(loop=loop, host=host, port=port, user=user, password=password, db=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
async def init(loop): await create_pool(loop=loop, host=configs.db.host, port=configs.db.port, user=configs.db.user, password=configs.db.password, db=configs.db.db) app = web.Application(loop=loop, middlewares=[ logger_factory, auth_factory, data_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(), configs.web.host, configs.web.port) logging.info('server started at http://%s:%d...' % (configs.web.host, configs.web.port)) return srv
async def init(loop): await orm.create_pool(loop=loop, host='127.0.0.1', port=3306, user='******', password='******', db='py_test') 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) app.on_shutdown.append(on_close) # srv = await loop.create_server(app.make_handler(), '127.0.0.1', 9000) handler = app.make_handler() srv = await loop.create_server(handler, '127.0.0.1', 9000) rs = dict() rs['app'] = app rs['srv'] = srv rs['handler'] = handler logging.info('server started ad http://127.0.0.1:9000...') return rs