Use of knowledge points: Logging, Asyncio, aiohttp modules (follow-up supplementary knowledge points)
"""app.py writing web App skeleton"""ImportLogging Logging.basicconfig (level=logging.info)ImportAsyncio fromAiohttpImportWebasyncdefIndex (Request):"""response Function""" returnWeb. Response (body=b'', content_type='text/html') Asyncdefinit (loop):"""Web App Server initialization""" #Making Response CollectionsApp = web. Application (loop=loop)#Add a response function to the Response function collectionApp.router.add_route (method='GET', path='/', handler=index)#Create server (connection URL, port, bind handler)SRV = await loop.create_server (App.make_handler (),'127.0.0.1', 9000) Logging.info ('server start at http://127.0.0.1:9000') returnSRV#Create Eventloop =Asyncio.get_event_loop ()#RunLoop.run_until_complete (init (loop))#server does not shut downLoop.run_forever ()
Python_web_app_day_1: Writing a Web App skeleton