It is impossible to build a whole page using only genshi.builder.tag- you will need to perform some operation on the resulting stream to insert a doctype. Also, the resulting code would look awful. The recommended way to use Genshi is to use a separate template file, generate a stream from it, and then convert this stream to the desired type of output.
genshi.builder.tag , Python, , - .
. :
, builder.tag, ( ) :
from itertools import chain
from genshi.core import DOCTYPE, Stream
from genshi.output import DocType
from genshi.builder import tag as t
page = t.html (t.head (t.title ("Hello world!")), t.body (t.div ("Body text")))
stream = page.generate ()
stream = Stream (chain ([(DOCTYPE, DocType.get ('html4'), None)], stream))
text = stream.render ('html')
- , , . .