/examples/web/makotemplates.py
https://bitbucket.org/prologic/circuits/ · Python · 42 lines · 28 code · 13 blank · 1 comment · 1 complexity · d7c9627e261c185671e41c7178c34a62 MD5 · raw file
- #!/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()