我想从 html 表单创建 xml 文件。我正在使用 django,我想在我的 xml 文件中插入 html 表单数据。
我的 html 表单中有以下字段:
复选框列表
用于从日历中插入日期的文本框
<input type="file" file-accept="pdf, doc, docx, xls, csv, txt, rtf, html, zip, mp3, wma, mpg, flv, avi, jpg, jpeg, png, gif" file-maxsize="10240" />
你能指导我怎么做吗?非常感谢您的回答。
最佳答案
from xml.etree.ElementTree import Element, SubElement, Comment, tostring
top = Element('top')
comment = Comment('Generated for PyMOTW')
top.append(comment)
child = SubElement(top, 'child')
child.text = 'This child contains text.'
child_with_tail = SubElement(top, 'child_with_tail')
child_with_tail.text = 'This child has regular text.'
child_with_tail.tail = 'And "tail" text.'
child_with_entity_ref = SubElement(top, 'child_with_entity_ref')
child_with_entity_ref.text = 'This & that'
print tostring(top)
这是您可以在 python 中创建 xml 文件并将 html 数据放在需要的地方的方式
除此之外,您还可以对 xml 使用 Django 序列化
关于html - 如何在 django 中从 html 表单创建 xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12121407/