我的视图中有一个功能可以在背景中裁剪成千上万张图像:
def run_task(request):
initialize()
return render(request,'home/index.html')
def postpone(function):
def decorator(*args, **kwargs):
t = Thread(target = function, args=args, kwargs=kwargs)
t.daemon = True
t.start()
return decorator
@postpone
def initialize():
allimages = []
number = 0
if not os.path.exists('thumbnails'):
os.makedirs('thumbnails')
path = '/Users/shoaibrafa/Data/*.jpg'
for image in glob.glob(path):
print(image,"=====",number)
im = Image.open(image)
im.thumbnail((512, 512), Image.ANTIALIAS)
im.save("thumbnails/" + os.path.basename(image), "JPEG")
number = number + 1
我的问题是,如何在模板(index.html)中显示到目前为止已处理了多少张图像!或者只是如何在每次迭代中将“数字”值发送到模板?
预先感谢