Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add not found and server error pages

  • Loading branch information...
commit 7dec9cf08e7192f9eb1e681cdd63efcfd972f234 1 parent 7055b6d
David Xie authored
4 davidblog/davidblog.py
View
@@ -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:
10 davidblog/static/css/styles.css
View
@@ -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 davidblog/templates/notfound.html
View
@@ -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 davidblog/templates/notfoundPage.html
View
@@ -1,7 +0,0 @@
-<%inherit file="base.html" />
-
-<%def name="title()">页面不存在</%def>
-
-<div id="erro_message">
- <p>您好, 您所访问的页面并不存在, 请核对地址后重新访问</p>
-</div>
28 davidblog/templates/servererror.html
View
@@ -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 davidblog/views.py
View
@@ -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
@@ -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>' \
@@ -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())
Please sign in to comment.
Something went wrong with that request. Please try again.