Bundled cherrypy.
[smonitor.git] / monitor / cherrypy / scaffold / __init__.py
blob00964ac5f6cc46c214f0b22f329d4cd1c004a1be
1 """<MyProject>, a CherryPy application.
3 Use this as a base for creating new CherryPy applications. When you want
4 to make a new app, copy and paste this folder to some other location
5 (maybe site-packages) and rename it to the name of your project,
6 then tweak as desired.
8 Even before any tweaking, this should serve a few demonstration pages.
9 Change to this directory and run:
11 ../cherryd -c site.conf
13 """
15 import cherrypy
16 from cherrypy import tools, url
18 import os
19 local_dir = os.path.join(os.getcwd(), os.path.dirname(__file__))
22 class Root:
24 _cp_config = {'tools.log_tracebacks.on': True,
27 def index(self):
28 return """<html>
29 <body>Try some <a href='%s?a=7'>other</a> path,
30 or a <a href='%s?n=14'>default</a> path.<br />
31 Or, just look at the pretty picture:<br />
32 <img src='%s' />
33 </body></html>""" % (url("other"), url("else"),
34 url("files/made_with_cherrypy_small.png"))
35 index.exposed = True
37 def default(self, *args, **kwargs):
38 return "args: %s kwargs: %s" % (args, kwargs)
39 default.exposed = True
41 def other(self, a=2, b='bananas', c=None):
42 cherrypy.response.headers['Content-Type'] = 'text/plain'
43 if c is None:
44 return "Have %d %s." % (int(a), b)
45 else:
46 return "Have %d %s, %s." % (int(a), b, c)
47 other.exposed = True
49 files = cherrypy.tools.staticdir.handler(
50 section="/files",
51 dir=os.path.join(local_dir, "static"),
52 # Ignore .php files, etc.
53 match=r'\.(css|gif|html?|ico|jpe?g|js|png|swf|xml)$',
57 root = Root()
59 # Uncomment the following to use your own favicon instead of CP's default.
60 #favicon_path = os.path.join(local_dir, "favicon.ico")
61 #root.favicon_ico = tools.staticfile.handler(filename=favicon_path)