Python Web S1E1 : Cherrypy – HelloWorld

Python Web S1E1 : Cherrypy – HelloWorld



Rating : No ratings yet.




Introduction

Cherrypy is an object oriented web framework that is quite clean and minimalistic. This is makes it easy to pick up. The best thing about it is that it allows you build your web applications in the same way you would build any of your application when using the Object Oriented Paradigm. With this framework you write smaller source code to get things done.
We are going to cover alot of tutorials about Cherrypy. This is our first, hello world application. It's mainly to do with installation and writing our first hello world app that routes functions to differnt urls to output basic html.
Cherypy doesn't require any special requirements for it to be installed or run. It can run anywhere python can run:

Install it using any of the following commands:

$ easy_install cherrypy
$ pip install cherrypy

 

You can also get it from github:

$ git clone https://github.com/cherrypy/cherrypy
$ cd cherrypy
$ python setup.py install

 

For more information on cherrypy installation please here is detailed guide.

Tools Used

Language : Python 3.5, HTML
Platform : Backend and Fronted Web
IDE : PyCharm
Topics : Object Oriented Python, Cherrypy install,Cherrypy hello world, Cherrypy Routing

Questions this Project answers.

  • How to install Cherrypy.
  • CherryPy web development example
  • Cherrypy Routing example

Libraries Used

These are the third party CSS and JS used in this project.

  • None.

Screenshot

  • Here's the screenshot of the project.
    CherryPy Hello World

Project Structure

  • Here's the structure of the project.

CherryPy HelloWorld Project Structure

Source Code

Lets have a look at the source code.

Index.pyVideo/DemoDownload
  • Our Main class.
  • We route different methods to urls here.
  • We'll have two methods: index and about function which will each be mapped to different urls.
import cherrypy
class Index(object):
    @cherrypy.expose()
    def index(self):
        return open('index.html')
    @cherrypy.expose()
    def about(self):
        return """
               <html>
               <head><title>About Us</title></head>
               <body>
               <h1>About Us</h1>
               <p>This is our first python class.This is about us page</p>
               </body>
               </html>
               """
if __name__=='__main__':
    cherrypy.quickstart(Index())

 

  • Video version of this tutorial.

Python Web S1E1 : CherryPy - Hello World

  • Download the Project below:
Download

How to Download and Run.

  1. Download the project above.
  2. You'll get a zipped file,extract it.
  3. Import into your IDE and run.

More

  • Visit our channel for more examples like these.
  • Lets share tips and ideas in our Facebook Page.

Oclemy,Cheers.



Rating :

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    6 + twenty =

    COMMENTS