你能帮我吗? 如何在应用程序中显示进度栏? 我从数据库获取值并创建所有值组合的列表,然后将文件名保存到数据库并将xml文件保存到磁盘。此操作需要很长时间。我想显示进度条,已经创建了多少文件。进度栏必须保持最新。
def save_auto_xml_tests(request, pk):
serial_port_speed = list(SerialPortSpeed.objects.values_list('value', flat=True))
serial_port_data_bits = list(SerialPortDataBits.objects.values_list('value', flat=True))
serial_port_parity = list(SerialPortParity.objects.values_list('value', flat=True))
serial_port_stop_bits = list(SerialPortStopBits.objects.values_list('value', flat=True))
serial_port_handshake = list(SerialPortHandshake.objects.values_list('value', flat=True))
created = list(itertools.product(serial_port_speed, serial_port_data_bits, serial_port_parity, serial_port_stop_bits, serial_port_handshake))
for item in created
seeker = Seeker.objects.get(name=modelseeker)
xml_file_name = time.strftime("%Y%m%d-%H%M%S") + '.xml'
record = XmlSeeker(xml_file=xml_file_name)
record.save()
xml_body = "..."
xml_seeker_test = 'XmlGenerated\\{}\\{}'.format(pk, xml_file_name)
pathlib.Path('./media/XmlGenerated/{}/'.format(pk)).mkdir(parents=True, exist_ok=True)
f = open(os.path.join(settings.MEDIA_ROOT, xml_seeker_test), 'w')
xml_save = ET.ElementTree(ET.fromstring(xml_body))
xml_save.write(os.path.join(settings.MEDIA_ROOT, xml_seeker_test), encoding="UTF-8", xml_declaration=True)
f.close()
return redirect('details', pk=pk)