永无止境的Django网袋

永无止境的Django网袋,django,websocket,Django,Websocket,有一个页面有一个按钮,我可以单击该按钮并通过Websocket在服务器上启动该过程。我通过Websocket获得有关流程的信息。在没有断开连接的情况下,如何关闭并重新打开页面以查看进程的当前状态(不是一开始) async def worker_status(send): for i in range(numbers): some_function() await asyncio.sleep(1) async def websocket_application(scope, re

有一个页面有一个按钮,我可以单击该按钮并通过Websocket在服务器上启动该过程。我通过Websocket获得有关流程的信息。在没有断开连接的情况下,如何关闭并重新打开页面以查看进程的当前状态(不是一开始)

async def worker_status(send):
for i in range(numbers):
    some_function()
    await asyncio.sleep(1)

async def websocket_application(scope, receive, send):
while True:
    event = await receive()
    if event['type'] == 'websocket.connect':
        await send({
            'type': 'websocket.accept'
        })
    if event['type'] == 'websocket.disconnect':
        break
    if event['type'] == 'websocket.receive':
        if event['text'] == 'StartAct':
            loop = asyncio.get_event_loop()
            loop.create_task(worker_status())
            await send({
                'type': 'websocket.send',
                'text': str("In process")
            })
        if event['text'] == 'Status':
            await send({
                'type': 'websocket.send',
                'text': str("Ready to process")
            })

除非断开连接,否则WebSocket已经是持久连接。请提供代码和确切的问题。没错!但如果是这样的话,请重新连接