"Hello, World!" in CherryPy














































"Hello, World!" in CherryPy



Python: CherryPy

"HELLO, WORLD!" IN CHERRYPY

Since Brian Kernigham's 1972 book, A Tutorial Introduction to the Language B, "Hello, World!" has become a standard first program. So, we will start CherryPy too by writing a program to display "Hello, World!".

The below code starts a server at port number 8080 and hosts an application which will be served at request reaching http://127.0.0.1:8080/ or http://localhost:8080/

import cherrypy


class hello_world(object):
@cherrypy.expose
def index(self):
return "Hello, World!"


if __name__ == '__main__':
cherrypy.quickstart(hello_world())

This is the most basic application you could write with CherryPy. Save this code in a file named 'hello_world.py' and execute it in Terminal/Command Line as follows:

python3 hello_world.py

The output will look something like this:

[08/Sep/2020:12:17:54] ENGINE Listening for SIGTERM.
[
08/Sep/2020:12:17:54] ENGINE Bus STARTING
CherryPy Checker:
The Application mounted at
'' has an empty config.

[
08/Sep/2020:12:17:54] ENGINE Set handler for console events.
[
08/Sep/2020:12:17:54] ENGINE Started monitor thread 'Autoreloader'.
[
08/Sep/2020:12:17:54] ENGINE Serving on http://127.0.0.1:8080

[08/Sep/2020:12:17:54] ENGINE Bus STARTED

The first three lines indicate that the server will handle signals for you. The next line indicates the current state of the server which is in the STARTING stage. Then, it specifies that we are using default configuration. Next, the server starts a couple of internal utilities. Finally, the server indicates that it is now ready to accept incoming communications as it listens on the address 'http://127.0.0.1:8080'.

Now, open a browser window and enter http://127.0.0.1:8080/ or http://localhost:8080/ in the address bar. The result will be like this


More Articles of Aniket Sharma:

Name Views Likes
Pyperclip: Installation and Working 966 2
Number Guessing Game using Python 656 2
Pyperclip: Not Implemented Error 957 2
Hangman Game using Python 16192 2
Using Databases with CherryPy application 1594 2
nose: Working 488 2
pytest: Working 490 2
Open Source and Hacktoberfest 851 2
Managing Logs of CherryPy applications 949 2
Top 20 Data Science Tools 654 2
Ajax application using CherryPy 778 2
REST application using CherryPy 639 2
On Screen Keyboard using Python 5083 2
Elastic Net Regression 778 2
US Presidential Election 2020 Prediction using Python 776 2
Sound Source Separation 1131 2
URLs with Parameters in CherryPy 1547 2
Testing CherryPy application 603 2
Handling HTML Forms with CherryPy 1364 2
Applications of Natural Language Processing in Businesses 489 2
NetworkX: Multigraphs 616 2
Tracking User Activity with CherryPy 1305 2
CherryPy: Handling Cookies 767 2
Introduction to NetworkX 613 2
TorchServe - Serving PyTorch Models 1239 2
Fake News Detection Model using Python 701 2
Keeping Home Routers secure while working remotely 462 2
Email Slicer using Python 2947 2
NetworkX: Creating a Graph 1078 2
Best Mathematics Courses for Machine Learning 530 2
Hello World in CherryPy 643 2
Building dependencies as Meson subprojects 915 2
Vehicle Detection System 1052 2
NetworkX: Examining and Removing Graph Elements 575 2
Handling URLs with CherryPy 515 2
PEP 8 - Guide to Beautiful Python Code 736 2
NetworkX: Drawing Graphs 588 2
Mad Libs Game using Python 617 2
Hosting Cherry applications 588 2
Top 5 Free Online IDEs of 2020 839 2
pytest: Introduction 512 2
Preventing Pwned and Reused Passwords 559 2
Contact Book using Python 2058 2
Introduction to CherryPy 521 2
nose: Introduction 487 2
Text-based Adventure Game using Python 2900 2
NetworkX: Adding Attributes 2104 2
NetworkX: Directed Graphs 995 2
Dice Simulator using Python 539 2
Decorating CherryPy applications using CSS 769 2

Comments