CherryPy Presentation Layer - cherryPy

What is CherryPy Presentation Layer?

The Presentation Layer will make sure that the communication passing over it aims the expected recipients. CherryPy keeps the working of presentation layer by different template engines.

The input of the page is taken by the template engine from the business login and processed to the final page which aims only the targeted audience.
Kid The Template Engine

Kid is a easy template engine which comprises of the name of the template to be processed and input of the data to be passed when the template is returned.

  • When you are creating the template for the first time, Kid generates a python module which serves the purpose of cached version of template.
  • The kid.Template function will give an instance of the template class which can be utilized to submit the output content.

The template class offers the below set of commands −


Command and description



It returns the output content in the form of a string



It returns the output content as an iterator



The output content is dumped into a file object by it.

The parameters these commands used are as follows -



It informs how to encode the output content



It is a Boolean value which tells to XML prolog or Doctype



The content is rendered by this type of serialization


Let us consider below example to understand the working of Kid –

The next step after saving the file is to process the template via the Kid engine.

What are Kid’s attributes?

Below are the Kid’s attributes −

XML-Based Templating Language

Kid is an Extensible Markup Language(XML) based language. A Kid template should be a well-formed XML document with correct naming conventions.

Kid puts attributes within the XML elements to upgrade the underlying engine on the action to be followed for attaining the element. Kid has come up with its own name space in order to sustain overlapping with other current attributes within the XML document.

Variable Substitution:

Kid has come up with a variable substitution strategy and a simple approach — ${variable-name}.

These variables can either be used as attributes of elements or as the text content of an element. The variable will be evaluated by Kid each and every time when the execution takes place.

If the user wants the output of a literal string as ${something}, it can be left behind using the variable substitution by doubling the dollar sign.

Conditional Statement:

The below syntax is used for toggling various cases in the template–

In the above code, tag means the name of the element, for example DIV or SPAN.

In the place of “expression” in the code, we will place a Python expression. As a Boolean expression evaluates to either true or false, If it results true then the output will be included in the output content otherwise it will be excluded from the output content.

Looping Mechanism

The below syntax is used for looping an element in Kid –

In the above code, tag means the name of the element. The expression here is a Python expression, for instance for value in [...].


The below code shows the working of looping mechanism –


CherryPy Presentation Layer

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

cherryPy Topics