So you have an HTML code as input and would like to change some tags to some others ones. But why? You should never had the need to build the HTML page from another HTML page in web2py. You should rather simply combine the data and a view. In your example, the view could be this:
pages.css --------------- .page { page-break-after: always; } pages.html ---------------- {{ for page in pages: }} {{=DIV(page.content, _class="page")}} And if you really need to process the HTML, you should use an HTML parser e.g. lxml or html5lib.