diff --git a/demo/views/frontend.py b/demo/views/frontend.py index 5a54784..82e2ea7 100644 --- a/demo/views/frontend.py +++ b/demo/views/frontend.py @@ -15,6 +15,8 @@ async def time_response(ws: WebSocketResponse, delay: int = 60): await asyncio.sleep(delay) except ConnectionResetError: await asyncio.sleep(delay) + + @template('index.html') async def index(request): return {} @@ -24,28 +26,31 @@ async def index_2(request): return {} + async def websocket_handler(request): - ws: WebSocketResponse = WebSocketResponse() - await ws.prepare(request) - asyncio.create_task(time_response(ws)) - async for msg in ws: - - if msg.type == aiohttp.WSMsgType.TEXT: - - if msg.data == 'close': - await ws.close() - else: - await ws.send_str(f'Вы послали: {msg.data}') - elif msg.type == WSMsgType.ERROR: - print('ws connection closed with exception %s' % - ws.exception()) + ws: WebSocketResponse = WebSocketResponse() + await ws.prepare(request) + asyncio.create_task(time_response(ws)) + async for msg in ws: + + if msg.type == aiohttp.WSMsgType.TEXT: + + if msg.data == 'close': + await ws.close() + else: + await ws.send_str(f'Вы послали: {msg.data}') + elif msg.type == WSMsgType.ERROR: + print('ws connection closed with exception %s' % + ws.exception()) + + print('websocket connection closed') + + return ws - print('websocket connection closed') - return ws async def button_clicked(request): - data = await request.post() - text = data.get('text') - response_text = f'Вы ввели: {text}' - print(response_text) - return Response(text=response_text) \ No newline at end of file + data = await request.post() + text = data.get('text') + response_text = f'Вы ввели: {text}' + print(response_text) + return Response(text=response_text) \ No newline at end of file