Genshi is a
template engine for
XML
Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing data. It defines a set of rules for encoding electronic document, documents in a format that is both human-readable and Machine-r ...
-based vocabularies written in
Python. Genshi is used to easily insert generated output into XML-based languages, usually
HTML
Hypertext Markup Language (HTML) is the standard markup language for documents designed to be displayed in a web browser. It defines the content and structure of web content. It is often assisted by technologies such as Cascading Style Sheets ( ...
, and reuse elements between documents. Genshi's syntax is based on
Kid, but its architecture is different. Genshi aims to implement some of its functionality while processing templates faster, by dynamically processing templates using a stream based API, instead of compiling templates to Python code.
Genshi can be used with several Python
web framework
A web framework (WF) or web application framework (WAF) is a software framework that is designed to support the development of web applications including web services, web resources, and web APIs. Web frameworks provide a standard way to build a ...
s, such as
CherryPy
CherryPy is an object-oriented web application framework using the Python (programming language), Python programming language. It is designed for Rapid application development, rapid development of web applications by wrapper pattern, wrapping th ...
,
TurboGears
TurboGears is a Python web application framework consisting of several WSGI components such as WebOb, SQLAlchemyKajikitemplate language and Repoze.
TurboGears is designed around the model–view–controller (MVC) architecture, much like ...
,
Pylons and
web2py
Web2py is an open-source web application framework written in the Python programming language. Web2py allows web developers to program dynamic web content using Python. Web2py is designed to help reduce tedious web development tasks, such a ...
. Genshi was the default templating language for TurboGears from versions 1.1 to 2.3.8.
Genshi markup
Genshi makes use of
namespaces
In computing, a namespace is a set of signs (''names'') that are used to identify and refer to objects of various kinds. A namespace ensures that all of a given set of objects have unique names so that they can be easily identified.
Namespaces ...
to embed instructions into HTML. A typical instruction is given as an
attribute, with a Python expression inside the quotes. For example, the following will render a paragraph that shows 4:
This will be replaced with 4
Because of the use of namespaces, Genshi can be used in
WYSIWYG
In computing, WYSIWYG ( ), an acronym for what you see is what you get, refers to software that allows content to be edited in a form that resembles its appearance when printed or displayed as a finished product, such as a printed document, web ...
HTML editor
An HTML editor is a program used for editing HTML, the markup of a web page. Although the HTML markup in a web page can be controlled with any text editor, specialized HTML editors can offer convenience, added functionality, and organisation. Fo ...
s.
Differences between Kid and Genshi
* Genshi directly interprets templates (unlike Kid, which generates Python code)
* Genshi uses
XInclude for template reuse
* Genshi adds attributes Kid does not have, like
py:choose
* Genshi templates are easier to debug, because it tracks template source file names and line numbers, and errors from Genshi's interpreter produce more comprehensible stack traces than from Kid's
generated code.
References
External links
*
{{DEFAULTSORT:Genshi (Templating Language)
Free system software
Free software programmed in Python
Python (programming language) software
Scripting languages
Python (programming language) libraries
Template engines