0% found this document useful (0 votes)
20 views

Web Programming with CherryPy

Uploaded by

answer.provider
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Web Programming with CherryPy

Uploaded by

answer.provider
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

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.

Simple Search Engine


<html>
<head>
<title>Simple Search Engine</title>
</head>
<body>
<h3>Simple Search Engine</h3>
<form action="http://www.google.com/search">
<input type="text" name="q">
<input type="submit">
</body>
</html>
Post Data to another Page

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=="-"):

return "Difference: " + str(intNum1-intNum2)

if(select1=="*"):

return "Product: " + str(intNum1*intNum2)

if(select1=="/"):

return "Quotient: " + str(intNum1/intNum2)

doCalc.exposed=True

cherrypy.quickstart(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>

You might also like