diff options
Diffstat (limited to '')
-rwxr-xr-x | index.py | 27 |
1 files changed, 17 insertions, 10 deletions
@@ -13,6 +13,8 @@ import helper APPDIR = os.path.dirname(os.path.abspath(__file__)) +app = web.auto_application() + def appdir (*args): return os.path.join(APPDIR, *args) @@ -24,31 +26,36 @@ class Renderer: output_encoding='utf-8', format_exceptions = True) - def render (self, tpl, **kwargs): + def render (self, tpl, level = "pages" , **kwargs): try: - t = self.get_tpl(tpl) + t = self.get_tpl(tpl, level) except mako.exceptions.TopLevelLookupException, e: - raise web.notfound(e) + raise app.notfound(tpl) return t.render(h = helper, url = helper.url, w = web, **kwargs) __call__ = render - def get_tpl (self, tpl): - return self.lookup.get_template(self.get_tpl_name(tpl)) + def get_tpl (self, tpl, level): + return self.lookup.get_template(self.get_tpl_name(tpl, level)) - def get_tpl_name (self, tpl): + def get_tpl_name (self, tpl, level): if not tpl.endswith(".mako"): tpl = tpl+".mako" - return os.path.join("pages", tpl) + return os.path.join(level, tpl) -urls = ("/(.*)", "Handler") -app = web.application(urls, globals()) +web.config.debug = True render = Renderer() -class Handler: +def FourOhFour(page): + return web.notfound(render("404", level = "", page = page)) + +app.notfound = FourOhFour + +class Handler (app.page): + path = "/(.*)" def GET(self, name = '/'): if not name or name == '/': name = 'index' return render(name) |