我正嘗試使用pySmartDL構建基於瓶子的下載管理器。 但是,我無法在下載過程中將進度條輸出到瀏覽器。Python Bottle web應用程序在瀏覽器中實時顯示輸出
app.py
from bottle import route, run, debug, template, request, static_file, error
import os
from pySmartDL import SmartDL
@route('/static/:filename#.*#')
def send_static(filename):
return static_file(filename, root='./static/')
@route('/',method='GET')
def index():
return template('index.tpl')
@route('/download/', method='POST')
def result():
if request.POST.get('url','').strip():
url = request.POST.get('url', '').strip()
#url = "http://mirror.ufs.ac.za/7zip/9.20/7za920.zip"
dest = "C:\\Downloads\\" # or '~/Downloads/' on linux
obj = SmartDL(url, dest)
obj.start(blocking=None)
# [*] 0.23 Mb/0.37 Mb @ 88.00Kb/s [##########--------] [60%, 2s left]
path = obj.get_dest()
out = template('out',out=obj.get_progress_bar(length=20),path=path)
return out
@error(500)
def mistake500(code):
return '<h3>Error!</h3>'
debug(True)
run(host='localhost', port=8080)
一旦文件被下載,#############被印刷在瀏覽器中。
out.tpl
% include('header.tpl', title='VTU Results Hub')
<table class="pure-table">
{{out}}
{{path}}
</table>
% include('footer.tpl')
有沒有什麼辦法讓我可以實時顯示在瀏覽器上的進度條。