summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.net>2010-03-16 23:41:07 +0100
committerRené 'Necoro' Neumann <necoro@necoro.net>2010-03-16 23:41:07 +0100
commit33ba646433a3696b29bc57f107694457d6a20e2e (patch)
tree5a0b5c0934a22033cb32ab1d317566b34d354d31
parent667dcbf5d4149e5aae07b855afb60718fafb3ffb (diff)
downloadweb-33ba646433a3696b29bc57f107694457d6a20e2e.tar.gz
web-33ba646433a3696b29bc57f107694457d6a20e2e.tar.bz2
web-33ba646433a3696b29bc57f107694457d6a20e2e.zip
Add a 404 page
-rwxr-xr-xindex.py27
-rw-r--r--templates/404.mako7
2 files changed, 24 insertions, 10 deletions
diff --git a/index.py b/index.py
index a6775f3..eda595c 100755
--- a/index.py
+++ b/index.py
@@ -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)
diff --git a/templates/404.mako b/templates/404.mako
new file mode 100644
index 0000000..aeb95e3
--- /dev/null
+++ b/templates/404.mako
@@ -0,0 +1,7 @@
+<%!
+ title = "404 -- Page not found!"
+%>
+<%inherit file="/page.mako" />
+<p>
+Sorry - the requested page <i>${page}</i> cannot be found.
+</p>