How to Redirect Stdout to Streaming Response in Django

Sometimes we need to execute some long tasks at the backend, and the tasks are complicated and error-prone. So we hope users can see the real-time console log. Thus we need to redirect the stdout in our functions to the user’s browser. Given a function like the following. How to see the stdout in real-time in the browser? import time def job(times): for i in range(times): print(f'Task #{i}') time.sleep(1) print('Done') time....

May 25, 2021 · 5 分钟 · wancat