Hi,
I finally found what I sought, without coding errors with special
chars.
The idea is to use the 404 page with a default template and can add
items to this 404 page while retaining the default template.
I do not know if my code is correct, but it seems to work. Is this the
right way?
In code.py:
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import web
web.config.debug = False
urls = (
'/', 'index',
'/test', 'test',
'/otherpage', 'otherpage',
)
app = web.application(urls, globals())
render = web.template.render('templates', globals={})
def notfound():
return web.notfound(render.notfound(text = u"Default Error
Page",
goto = u"/", link_text = "Back to index page...", special_caract =
"êéäß ... ∀y.∃α. f(α, y) ∊ Γ" ))
app.notfound = notfound
class index:
""" Simple index"""
def GET(self):
web.header('Content-type','text/html')
return '<h3>Hello</h3><br><a href="/hjfdsjkf">Go to
stupid page</
a><br>This page will return the standard 404 page.<br><a href="/
test">Go to Test page</a><br>This page will return a customized 404
page with a special link.'
class test:
""" This page return a 404 """
def GET(self):
raise web.notfound(render.notfound(text = u"Custom
Error Page",
goto = u"/otherpage", link_text = "Go to another page...",
special_caract = "êéäß ... ∀y.∃α. f(α, y) ∊ Γ"))
class otherpage:
""" Just a other page"""
def GET(self):
web.header('Content-type','text/html')
return '<h3>Other page</h3><br><a href="/">Back to
index page...</
a>'
if __name__ == "__main__":
app.run()
In / templates / notfound.html:
$def with (text, goto, link_text, special_caract)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>404 Not Found</title>
</head>
<body>
<h1>$text</h1>
<p>Special characters : $special_caract<br><a href="$goto">
$link_text</a></p>
<hr>
<address>Webpy 0.34</address>
</body>
</html>
--
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/webpy?hl=en.