python from genshi.template import MarkupTemplate template = MarkupTemplate(''' <html> <head> <title>${title}</title> </head> <body> <h1>${heading}</h1> <ul> <li py:for="item in items">${item}</li> </ul> </body> </html> ''') data = { 'title': 'Genshi Demo', 'heading': 'Welcome to Genshi', 'items': ['Item 1', 'Item 2', 'Item 3'] } html = template.generate(**data).render('xhtml') print(html) python { "genshi.directories": "/path/to/templates", "genshi.default_encoding": "utf-8", "genshi.default_formatter": "xhtml", "genshi.default_doctype": "html", "genshi.default_excludes": ["py"] }


上一篇:
下一篇:
切换中文