import asyncio import aiohttp from aiohttp import WSMsgType from aiohttp.web_response import Response from aiohttp.web_ws import WebSocketResponse from aiohttp_jinja2 import template from ..func import secondary_functions @template('index.html') async def index(request): return {} @template('index_2.html') async def index_2(request): return {} async def websocket_handler(request): ws: WebSocketResponse = WebSocketResponse() await ws.prepare(request) asyncio.create_task(secondary_functions.time_response(ws, delay=60)) async for msg in ws: if msg.type == aiohttp.WSMsgType.TEXT: 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 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)