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 [Link]
-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 [Link]
install
-To test if the cherrypy framework is installed properly, type import cherrypy in the
python shell.
Simple Search Engine
<html>
<head>
<title>Simple Search Engine</title>
</head>
<body>
<h3>Simple Search Engine</h3>
<form action="[Link]
<input type="text" name="q">
<input type="submit">
</body>
</html>
Post Data to another Page
Import cherrypy
class Calculator:
def index(self):
fx=open("[Link]","r")
webform=[Link]()
returnwebform
[Link]=True
defdoCalc(self,num1=None,num2=None,select1=None):
intNum1=int(num1)
intNum2=int(num2)
if(select1=="+"):
return "Sum: " + str(intNum1+intNum2)
if(select1=="-"):
return "Difference: " + str(intNum1-intNum2)
if(select1=="*"):
return "Product: " + str(intNum1*intNum2)
if(select1=="/"):
return "Quotient: " + str(intNum1/intNum2)
[Link]=True
[Link](Calculator())
<html>
<head>
<title>Calculator</title>
</head>
<body>
<form action="doCalc" method="post">
First number:
<input type="text" name="num1"></input>
<select name="select1">
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
</select>
Second number:
<input type="text" name="num2"></input>
<input type="submit" value="Compute"></input>
</body>
</html>