CherryPy A working application - cherryPy

Explain a CherryPy Working Application?

Full stack applications facilitates a provision to design a new application through some command or execution of the file.

Take an example of Python applications like web2py framework; the complete project/application is designed in Model View Controller (MVC) framework. In the same way, CherryPypermits the user to set up and configure code layout according to their requirements.

In this session, we will learn in detail the process of creating and executing the CherryPy application.

What is CherryPy File System?

The file system of the application is displayed in the below screenshot −

CherryPy File System

Let us see brief description of the differentfiles that are available in the file system −

  • − Every application needs a configuration file and a way to load it. This functionality can be defined in
  • − MVC is one of the most popular design pattern followed by the users. The is a file where all the objects are implemented that will be placed on the cherrypy.tree.
  • − This file communicates with the database directly for some services or for storing continous data.
  • − This file communicates with production finished web server that works well with load balancing proxy.
  • Static − It contains all the CSS and image files.
  • Views − It contains all the template files for a certain application.


Let us learn in detail the creation steps of a CherryPy application.

Step 1 − Create an application that must containCherryPy application.

Step 2 − In the directory, create a python package related to the project. Create a directorygedit and include file within the same.

Step 3 – Inthe package, include file with the below content –

Step 4 –Let us consider an application where the user inputs a value through a form. Let usadd two forms — index.html and submit.html in the application.

Step 5 − In the given code for controllers, we have index()function, which is a function by default loads if a particular controller is called.

Step 6 − The operation of the index() method can be altered in the below mentioned way −

Step 7 – This step will load index.html on starting the given application and instruct it to the given output stream. The index.html file is as shown below −


Step 8 − It is necessary to add a method to the Root class in if you desire to create a form which takes values such as titles and names.

Step 9 − The code to be inserted in submit.html is as shown below–

Step 10 − You will obtain the below output −

CherryPy File System Output

Here, the method name is defined as “POST”. It is always necessary to cross check the method mentioned in the file. If the method consists“POST” method, the values should be retested in the database in suitable fields.

If the method consists of “GET” method, the values to be saved will be seen in the URL.

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

cherryPy Topics