所以我有一个创建xml的基本脚本并将其添加到文件中:
from xml.etree.ElementTree import ElementTree
from xml.etree.ElementTree import Element
import xml.etree.ElementTree as etree
root = Element('ipaddress')
tree = ElementTree(root)
ipaddress = Element('ipaddress')
root.append(ipaddress)
ipaddress.text= **INSERT FROM FORM**
ipaddress.set('version', 'v4')
print etree.tostring(root)
tree.write("/root/Desktop/" + "xmlfile.xml")
它在xmlfile.xml
上显示如下<ipaddress><ipaddress version="v4">123.123.123.123</ipaddress></ipaddress>
我有一个简单的HTML Form元素来处理它:
<form action="create_ticket" method="post">
<div class="row">
<div class="col-lg-12">
<input type="text" size="35" placeholder="Host IP"
name="host_ip" class="form-control" required>
</div>
</div>
<input type="submit" value="Submit">
</form>
表格更大,输入更多,但这是基本想法。它还通过使用另一个脚本通过API提供票证。
如何根据用户在表单上输入host_ip的内容动态更改ipaddress.text值?
感谢您的帮助!