python - Show a message in Django after a function completes, without having the user wait for it to complete
问题描述
Say I have this view:
import threading
def MyView(request):
thr = threading.Thread(target=my_func, args=(request,))
thr.start()#Runs a function that the user should not wait for
return render(request, "my_site")
where
def my_func(request):
#Some function that takes 10 second and the user should not wait for this
sleep(10)
messages.success(request, "Your meal is ready!")
return render(request, "my_other_site")
What I want to do is; I have a function of which the user should not wait for to complete i.e they should be able to continue browsing, and then when the function is done, I want to show them a message either using messages
or a pop-up box or something third.
Is there a way to do that in Django (since it all runs synchronous I can't think of a way), or what would be the most optimal way (
解决方案
推荐阅读
- fluentvalidation - FluentValidation 未正确验证电子邮件地址列表?
- asp.net-core - asp.net core 2.2 brotli 压缩在 IIS 上不起作用?
- codeigniter - Codeigniter:当前未加载数据库驱动程序
- php - symfony 4 通过服务器在 dev 中运行时显示 500 错误“某事已损坏”:运行
- c++ - 如何获得对变体值的引用?
- postgresql - Postgres:删除外键约束查询卡住
- jquery - 在 ASP.NET 中使用 JQuery 删除 INPUT TAG 中的垂直对齐
- python - Python 未在 Windows 7 上安装 - 安装程序甚至不会出现
- python - 如何在列表中查找重复项?
- javascript - JavaScript 中的 POST 数据未发送