Python Web S1E1 : Cherrypy – HelloWorld
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.
Language : Python 3.5, HTML
Platform : Backend and Fronted Web
IDE : PyCharm
Topics : Object Oriented Python, Cherrypy install,Cherrypy hello world, Cherrypy Routing
- How to install Cherrypy.
- CherryPy web development example
- Cherrypy Routing example
These are the third party CSS and JS used in this project.
- Here's the screenshot of the project.
- Here's the structure of the project.
Lets have a look at the source code.
- 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.
- Download the Project below:
- Download the project above.
- You'll get a zipped file,extract it.
- Import into your IDE and run.
- Visit our channel for more examples like these.
- Lets share tips and ideas in our Facebook Page.