1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#!/usr/bin/env python
import os
import mako
from mako.lookup import TemplateLookup
from circuits.web import Server, Controller, Static
DEFAULTS = {}
templates = TemplateLookup(
directories=[os.path.join(os.path.dirname(__file__), "tpl")],
module_directory="/tmp",
output_encoding="utf-8"
)
def render(name, **d):
try:
d.update(DEFAULTS)
tpl = templates.get_template(name)
return tpl.render(**d)
except:
return mako.exceptions.html_error_template().render()
class Root(Controller):
tpl = "index.html"
def index(self):
return render(self.tpl)
def submit(self, firstName, lastName):
msg = "Thank you %s %s" % (firstName, lastName)
return render(self.tpl, message=msg)
app = Server(("0.0.0.0", 8000))
Static().register(app)
Root().register(app)
app.run()
|