Skip to content

Commit

Permalink
add not found and server error pages
Browse files Browse the repository at this point in the history
  • Loading branch information
David Xie committed Jun 8, 2010
1 parent 7055b6d commit 7dec9cf
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 16 deletions.
4 changes: 2 additions & 2 deletions davidblog/davidblog.py
Expand Up @@ -22,8 +22,8 @@

app.add_processor(web.loadhook(views.my_loadhook))
app.add_processor(views.my_handler)
#app.notfound = notfound
#app.internalerror = internalerror
app.notfound = views.notfound
app.internalerror = views.internalerror

def getSession():
if '_session' not in web.config:
Expand Down
10 changes: 10 additions & 0 deletions davidblog/static/css/styles.css
Expand Up @@ -194,3 +194,13 @@ body {
width:500px;
height:150px;
}

/** error and notfound page **/
#error_message {
color:white;
height:350px;
text-align:center;
}
#error_message p {
margin-top:150px;
}
28 changes: 28 additions & 0 deletions davidblog/templates/notfound.html
@@ -0,0 +1,28 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>页面不存在 - 泥泞的沼泽</title>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
<meta name="author" content="davidx, 灰太狼大王" />
<meta name="keywords" content="davidx, 灰太狼大王, 泥泞的沼泽, python, linux, webpy, web, php, yii, gentoo" />
<meta name="google-site-verification" content="OC2uStcVKMKlEuEvdxe8LHqfNWfMIVG5uDFMSgRgafo" />
<link rel="stylesheet" type="text/css" href="/static/css/styles.css" />
<link rel="stylesheet" type="text/css" href="/static/css/syntax.css" />
<link rel="SHORTCUT ICON" href="/static/favicon.ico" />
<script type="text/javascript" src="/static/js/jquery-1.3.2.min.js"></script>
</head>
<body>
{% include "_leftbar.html" %}
<div id="main">
<div id="error_message">
<p>您好, 您所访问的页面并不存在, 请核对地址后重新访问</p>
</div>
<div id="foot">
<p>如需转贴, 请注明出处. @转自<a href="http://davidx.me/">&lt;泥泞的沼泽:http://davidx.me/&gt;</a> | Powered by <a href="http://webpy.org/" target="_blank">web.py</a></p>
<p>版权所有©2009 <a href="http://davidx.me/">David Xie</a></p>
</div>
</div>
<br class="clearfloat" />
</body>
</html>
7 changes: 0 additions & 7 deletions davidblog/templates/notfoundPage.html

This file was deleted.

28 changes: 28 additions & 0 deletions davidblog/templates/servererror.html
@@ -0,0 +1,28 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>内部错误 - 泥泞的沼泽</title>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
<meta name="author" content="davidx, 灰太狼大王" />
<meta name="keywords" content="davidx, 灰太狼大王, 泥泞的沼泽, python, linux, webpy, web, php, yii, gentoo" />
<meta name="google-site-verification" content="OC2uStcVKMKlEuEvdxe8LHqfNWfMIVG5uDFMSgRgafo" />
<link rel="stylesheet" type="text/css" href="/static/css/styles.css" />
<link rel="stylesheet" type="text/css" href="/static/css/syntax.css" />
<link rel="SHORTCUT ICON" href="/static/favicon.ico" />
<script type="text/javascript" src="/static/js/jquery-1.3.2.min.js"></script>
</head>
<body>
{% include "_leftbar.html" %}
<div id="main">
<div id="error_message">
<p>您好, 服务器遇到了一个不可遇见的错误,请稍后再来</p>
</div>
<div id="foot">
<p>如需转贴, 请注明出处. @转自<a href="http://davidx.me/">&lt;泥泞的沼泽:http://davidx.me/&gt;</a> | Powered by <a href="http://webpy.org/" target="_blank">web.py</a></p>
<p>版权所有©2009 <a href="http://davidx.me/">David Xie</a></p>
</div>
</div>
<br class="clearfloat" />
</body>
</html>
14 changes: 7 additions & 7 deletions davidblog/views.py
Expand Up @@ -68,14 +68,14 @@ def getEntry(self, slug):
if slug:
entry = web.ctx.orm.query(Entry).filter_by(slug=slug).first()
i = web.input(page = 1)
commentCount = web.ctx.orm.query(Comment).filter_by(entryId=entry.id).count()
commentCount = web.ctx.orm.query(Comment).filter_by(entry_id=entry.id).count()
p = Pagination(int(commentCount), 5, int(i.page))
entry.comments = web.ctx.orm.query(Comment).filter_by(entryId=entry.id)[p.start:p.limit]
entry.comments = web.ctx.orm.query(Comment).filter_by(entry_id=entry.id)[p.start:p.limit]
return (entry, p)

def GET(self, slug):
entry, p = self.getEntry(slug)
entry.viewNum = entry.viewNum + 1
entry.view_num = entry.view_num + 1
f = commentForm()
d['p'] = p
d['entry'] = entry
Expand All @@ -88,8 +88,8 @@ def POST(self, slug):
f = commentForm()
if f.validates():
comment = Comment(entry.id, f.username.value, f.email.value, f.url.value, f.comment.value)
entry.commentNum = entry.commentNum + 1
entry.viewNum = entry.viewNum - 1
entry.comment_num = entry.comment_num + 1
entry.view_num = entry.view_num - 1
web.ctx.orm.add(comment)
emails = ['mykingheaven@gmail.com']
message = u'<p>您在&lt;泥泞的沼泽&gt;上回复的日志 "' + entry.title + u'" 又有新的回复了, 请您去看看.</p><p>' \
Expand Down Expand Up @@ -162,7 +162,7 @@ def GET(self):
return rss

def notfound():
return web.notfound("对不起, 您所访问的地址并不存在.")
return web.notfound(render.notfound())

def internalerror():
return web.internalerror("对不起, 网站遇到一个不可遇见的错误.")
return web.internalerror(render.servererror())

0 comments on commit 7dec9cf

Please sign in to comment.