2

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" />

これを行う方法を教えてください。あなたの答えに本当に感謝します。

4

1 に答える 1

0
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シリアル化も使用できます

于 2012-08-25T11:36:57.010 に答える