gpt4 book ai didi

python - Django 进度条

转载 作者:太空宇宙 更新时间:2023-11-03 11:32:37 27 4
gpt4 key购买 nike

我正在使用 Django 上传文件并使用

subprocess

The job takes roughly 15 seconds to run, and rather than having the user think the page is frozen, I'd like to show a progress bar.

I can figure out the AJAX to update the progress bar, but what I don't know how to do is return an HttpResponse while subprocess is running. Perhaps threading is the solution? I don't have any experience there. Can someone give me some guidance?

Here's the view:

def start_job(request):
if request.method == 'POST':
form = UploadForm(request.POST, request.FILES)
if form.is_valid() and form.is_multipart():
save_file(form.cleaned_data['file'])
subprocess.call(["Kitchen.bat", "/file:job.kjb"])
return HttpResponseRedirect('/success/')
else:
form = UploadForm()
return render_to_response('template.html')
启动 ETL 作业

最佳答案

感谢@Bula,django-celery是完美的解决方案。

这是一个很好的introductory video开始。

关于python - Django 进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14593926/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com