Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python html generator

Tags:

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.

like image 201
Meloun Avatar asked Oct 10 '09 16:10

Meloun


People also ask

Can Python generate HTML?

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.

How do I write HTML content in Python?

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 .


1 Answers

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

like image 102
Knio Avatar answered Sep 29 '22 09:09

Knio