Creating a skeleton CherryPy app

The rest of the files listed on the diagram above form a template of an application.

app_context.py

The Spring Python application context used to wire the generated application using decorator-driven PythonConfig

cherrypy-app.py

The main portion of the application that is runnable

controller.py

Contains the business logic of the application

view.py

Contains some the CherryPy rendering parts of the application

images

A subdirectory containing images used by the view layer of the application

  1. Before we create our CherryPy application, we are missing something. In the earlier screenshot, this plugin wasn't listed. We need to find it and install it. First, let's see how we can look up existing plugins.
    Creating a skeleton CherryPy app
  2. Seeing gen-cherrypy-app listed, let's install it using coily without touching a browser.
    Creating a skeleton CherryPy app
  3. Let's use the plugin to create a CherryPy application called sample_app. Since we just installed it, the plugin now shows up on coily's help menu. With that in place, we can then run the command to create sample_app.
    Creating a skeleton CherryPy app

    gen-cherrypy-app creates a directory named sample_app and copies the files listed above into it. It also does some transformations of the files, based on the argument sample_app.

    • It replaces all instances of ${name} in each file with sample_app
    • It replaces all instances of ${properName} in each file with Sample_app
    • It renames cherrypy-app.py as sample_app.py
  4. To run the app, switch to the sample_app directory, and run the main script.
    ./sample_app.py
    
    Creating a skeleton CherryPy app
  5. Now we can visit our running application at http://127.0.0.1:8080.
    Creating a skeleton CherryPy app
  6. Let's inspect app_context.py and see some of the key features wired by gen-cherrypy-app.
Creating a skeleton CherryPy app

This i s the root object being wired. The rest of the confi guration (not shown here) is mostly security confi guration steps.

Note

In Chapter 6, Securing your Application with Spring Python, it was pointed out that security configuration with Spring Python requires many steps. gen-cherrypy-app helps out by pre-wiring most of the security parts, allowing the user to modify as needed rather than build from scratch.

From here, we can log in with the hard-wired credentials to view our expandable application.

Creating a skeleton CherryPy app

Currently, there are no controller objects. However, it would take little effort to add such a layer, as demonstrated in the previous chapter's case study.

This plugin is simple enough that most of the work spent in improving this plugin can be focused on the template files. This tactic is very useful to build other templates for other types of application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.189.173