简体   繁体   English

"Django 进度条"

[英]Django progress bar

I'm using Django to upload a file and kick of an ETL job using我正在使用 Django 上传文件并使用 ETL 作业

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 .该作业大约需要 15 秒才能运行,而不是让用户认为页面已冻结,我想显示一个进度条

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.我可以找出 AJAX 来更新进度条,但我不知道该怎么做是在子进程运行时返回一个 HttpResponse 。 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')

Thanks @Bula, django-celery is the perfect solution. 感谢@ Bula, django-celery是完美的解决方案。

Here's a good introductory video to get started. 这是一个很好的入门视频

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM