| 1 |
"""<MyProject>, a CherryPy application. |
|---|
| 2 |
|
|---|
| 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. |
|---|
| 7 |
|
|---|
| 8 |
Even before any tweaking, this should serve a few demonstration pages. |
|---|
| 9 |
Change to this directory and run: |
|---|
| 10 |
|
|---|
| 11 |
python cherrypy\cherryd -c cherrypy\scaffold\site.conf |
|---|
| 12 |
|
|---|
| 13 |
""" |
|---|
| 14 |
|
|---|
| 15 |
import cherrypy |
|---|
| 16 |
from cherrypy import tools, url |
|---|
| 17 |
|
|---|
| 18 |
import os |
|---|
| 19 |
local_dir = os.path.join(os.getcwd(), os.path.dirname(__file__)) |
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
class Root: |
|---|
| 23 |
|
|---|
| 24 |
_cp_config = {'tools.log_tracebacks.on': True, |
|---|
| 25 |
} |
|---|
| 26 |
|
|---|
| 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 |
|---|
| 36 |
|
|---|
| 37 |
def default(self, *args, **kwargs): |
|---|
| 38 |
return "args: %s kwargs: %s" % (args, kwargs) |
|---|
| 39 |
default.exposed = True |
|---|
| 40 |
|
|---|
| 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 |
|---|
| 48 |
|
|---|
| 49 |
files = cherrypy.tools.staticdir.handler( |
|---|
| 50 |
section="/files", |
|---|
| 51 |
dir=os.path.join(local_dir, "static"), |
|---|
| 52 |
|
|---|
| 53 |
match=r'\.(css|gif|html?|ico|jpe?g|js|png|swf|xml)$', |
|---|
| 54 |
) |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
root = Root() |
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|