We have seen how to run an application and access it with a web browser, now let's have a look at the Python code needed to accomplish this. We will need to serve static files but in addition to those static files we want to generate the main HTML content dynamically. This isn't strictly necessary as we could have served it as a static file just as easily but it serves as a simple example of how to generate dynamic content:
Chapter2/nocontent.py
import cherrypy
import os.path
current_dir = os.path.dirname(os.path.abspath(__file__))
Tip
You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.
nocontent.py
starts off with importing the cherrypy
and os.path
modules. The latter is needed to determine the directory that nocontent.py
resides...