0

Based on this question: Object html representation in Django

Are there any simple ways to create html output using object representation with an emphasis on pure code and simplicity?

For example, create a form created by a combination of these objects: html, body, div, form, select, input, a, img

My idea of use is as follows:

html = ModuleTags.Html()
body = ModuleTags.Body()
html.addBody(body)

div = ModuleTags.Div()
body.addDiv(div)

form = ModuleTags.Form()
div.addForm(form)

select = ModuleTags.Select()
select.addOption("one", "value_one")
form.addSelect(select)

input = ModuleTags.Input()
input.checkbox("vaule", "name", True)
form.addInput(input)

...

a = ModuleTags.A()
a.href("url")

img = ModuleTags.Img()
img.src("url")

...

print(html)

And the output will be as follows:

<html>
<body>
<div>
<form>
<select>
<option value="value_one">one
</select>
<input type="checkbox" checked name="name" value="value">
</form>
</div>
</body>
</html>

(Distance with white space is not necessary.)

There is already a (simple) template class Form:, class Div: ... for each html tags in Object-Oriented Representation? Thx

Stilgar Dragonclaw
  • 127
  • 1
  • 1
  • 11

1 Answers1

0

You can use an xml library to do what you are trying here. This link has more info:

Creating a simple XML file using python

Answers here are more up-to-date: Best way to generate xml?

Layman
  • 597
  • 3
  • 16