fate Uber-Karma
![Uber-Karma Uber-Karma](images/05.gif)
![](http://www.ember-art.com/imgdir/Evil_bunny.gif)
Joined: 11 Sep 2003 Posts: 1178
|
Posted: Fri Nov 11, 2005 5:07 pm Post subject: CherryPy |
|
|
http://www.cherrypy.org/
Quote: | CherryPy is a pythonic, object-oriented web development framework.
CherryPy allows developers to build web applications in much the same way they would build any other object-oriented Python program. This usually results in smaller source code developed in less time.
CherryPy is now more than three years old and it is has proven very fast and stable. It is being used in production by many sites, from the simplest ones to the most demanding ones.
Oh, and most importantly: CherryPy is fun to work with ![Smile](images/smiles/icon_smile.gif) |
This is basically a webserver in Python(well to me at least for now). And yes it is fun. I've been playing around with this thing lately so I desided to remake my own website in CherryPy to see how big it would end up being.
The website has a main, links, about me, and gallery pages. It also has a default page not found thing for top level pages. The gallery page generates html based off file system structure: /images for images, /images/thumbnails for thumbnails. The filenames in both folders match. This makes it easy to do a gallery without a db.
This is my complete website code:
Code: | import os
import cherrypy
class Test:
@cherrypy.expose()
def default(self, type):
if type == "gallery":
return self.gallery()
elif type == "links":
return '''<a href="http://www.google.com">google link</a>'''
elif type == "main":
return "Welcome to my page!"
elif type == "about":
return "About me!"
else:
return "page not found"
def gallery(self):
dir = "C:/Documents and Settings/azhiga/Desktop/cherryPyExcersise/mySite/files/images/"
files = os.listdir( dir )
s = ""
count = 0
for f in files:
if(f.endswith(".jpg") or f.endswith(".gif")):
s+='''<a href="/showimage/'''+f+'''" onClick="window.open('/showimage/'''+f+'''', 'image', 'toolbar=no, directories=no, location=no,'''
s+='''status=yes, menubar=no, scrollbars=yes'); return false">'''
s+='''<img src="/thumbnails/'''+f+'''"></a>'''
count=count+1
if(count%5==0 and count!=0):
s+='<br/>'
return s
class Test_ShowImage:
@cherrypy.expose
def default(self, image):
str = '''<html><body style="text-align:center"><img id="image" src="/images/'''+image+'''"/>'''
str += '''<script>var w, h=500; if(document.getElementById("image").width < screen.width) w = document.getElementById("image").width+50;'''
str += '''if(document.getElementById("image").height < screen.height) h = document.getElementById("image").height+70; window.resizeTo(w,h);</script></body></html>'''
return str
cherrypy.root = Test()
cherrypy.root.showimage = Test_ShowImage()
#---configures this cherrypy to serve static files from these directories off root url
cherrypy.config.configMap.update({
'/images': {
'staticFilter.on': True,
'staticFilter.dir': r"C:\Documents and Settings\azhiga\Desktop\cherryPyExcersise\mySite\files\images"
},
'/thumbnails': {
'staticFilter.on': True,
'staticFilter.dir': r"C:\Documents and Settings\azhiga\Desktop\cherryPyExcersise\mySite\files\images\thumbnails"
}})
#---starts the server
cherrypy.server.start()
|
Provided you have both Python and CherryPy if you copy and paste this code into a .py file and run that file, CherryPy will spinup a webserver(to your config, default is localhost:8080) and you'll be able to run the site at that url.
Development Time? : 1 day in between other work stuff _________________ People's whole lives do pass before their eyes before they die. The process is called living.
Most of the time its easier to get along with people before you get to know them. |
|