I am looking for an easily implemented HTML generator for Python. I found HTML.py, but there is no way to add CSS elements (id, class) for table.
Python does not come with tools to generate HTML. If you want an advanced framework for structured HTML generation, I recommend Robin Friedrich's HTMLGen 2.2 (available at http://starship.python.net/crew/friedrich/HTMLgen/html/main.html), but I do not cover the package in this book.
Use open() and file. write() to write to an HTML file Use open(file, mode) with mode as "w" to create a new HTML file file or write to an existing one. Use file. write(data) to write data to the file .
Dominate is an HTML generation library that lets you easily create tags. In dominate, python reserved words are prefixed with an underscore, so it would look like this:
from dominate.tags import * t = div(table(_id="the_table"), _class="tbl") print(t) <div class="tbl"> <table id="the_table"></table> </div>
Disclaimer: I am the author of dominate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With