To get started, let's build the most basic of programs with CherryPy. By this, I mean, of course, the ubiquitous Hello World
program that we will use to say Hello Raspberry Pi!
. We will work through a few examples before we build a dashboard to display weather data using a modified version of the CurrentWeather
class from Chapter 13, Subscribing to Web Services.
To build the Hello Raspberry Pi!
web page, do the following:
- Open up Thonny from
Application Menu
|Programming
|Thonny Python IDE
. - Click on the
New
icon to create a new file.
- Type the following:
import cherrypy class HelloWorld(): @cherrypy.expose def index(self): return "Hello Raspberry Pi!" cherrypy.quickstart(HelloWorld())
- Ensure that the line,
cherrypy.quickstart(HelloWorld())
, is inline with theimport
andclass
statements. - Save the file as
HelloRaspberryPi.py
. - Run the file by clicking on the green
Run current script
button. - You should see the CherryPy...