Web Programming with CherryPy
Web Programming with CherryPy
-CherryPy is a minimalist Python web framework that allows web developers to build
web apps in the same way as building a python program.
-Can be downloaded from www.cherrypy.org
-To install cherrypy:
1. Extract the downloaded file and copy the extracted file to C:\Python27 folder.
2. Open command prompt>Go to the cherrypy folder then type Python setup.py
install
-To test if the cherrypy framework is installed properly, type import cherrypy in the
python shell.
Import cherrypy
class Calculator:
def index(self):
fx=open("webcalc.html","r")
webform=fx.read()
returnwebform
index.exposed=True
defdoCalc(self,num1=None,num2=None,select1=None):
intNum1=int(num1)
intNum2=int(num2)
if(select1=="+"):
return "Sum: " + str(intNum1+intNum2)
if(select1=="-"):
if(select1=="*"):
if(select1=="/"):
doCalc.exposed=True
cherrypy.quickstart(Calculator())
<html>
<head>
<title>Calculator</title>
</head>
<body>
First number:
<select name="select1">
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
</select>
Second number:
</body>
</html>