webpy开发笔记01-调试模式下异常捕捉问题

最近用webpy开发web应用,不出所料刚开始果然遇到很多未知问题,这里总结一下。

  调试模式下异常捕捉问题,在开发过程中我在操作数据库是老是遇到以下的这个问题(实际上所有异常都报这个错误...)

01 File "D:\����\eclipesWork\python\PyTest\src\web\debugerror.py", line 305, in debugerror
02     return web._InternalError(djangoerror())
03   File "D:\����\eclipesWork\python\PyTest\src\web\debugerror.py", line 295, in djangoerror
04     return t(exception_type, exception_value, frames)
05   File "D:\����\eclipesWork\python\PyTest\src\web\template.py", line 881, in __call__
06     return BaseTemplate.__call__(self, *a, **kw)
07   File "D:\����\eclipesWork\python\PyTest\src\web\template.py", line 808, in __call__
08     return self.t(*a, **kw)
09   File "D:\����\eclipesWork\python\PyTest\src\web\debugerror.pyc", line 153, in __template__
10     <ul class="traceback">
11   File "D:\����\eclipesWork\python\PyTest\src\web\template.py", line 825, in _escape
12     value = safeunicode(value)
13   File "D:\����\eclipesWork\python\PyTest\src\web\utils.py", line 348, in safeunicode
14     return obj.decode(encoding)
15   File "C:\Python27\lib\encodings\utf_8.py", line 16, in decode
16     return codecs.utf_8_decode(input, errors, True)
17 UnicodeDecodeError: 'utf8' codec can't decode byte 0xb9 in position 3: invalid start byte
这样的问题让我很是纠结因为我根本看不到具体是什么问题。解决方式建一个超类捕获GET与POST的异常.

01 # -*- coding: utf-8 -*-
02 '''
03 Created on 2013-11-19
04  
05 @author: 梁前武 QQ:1587790525
06 '''
07 class baseweb():
08     def myGET(self):
09         return "baseweb get"
10     def myPOST(self):
11         return "baseweb post"
12     def GET(self):
13         v=""
14         try:
15             v=self.myGET()
16         except Exception,e:
17             return "erro %s"%(e)
18         return v
19     def POST(self):
20         v=""
21         try:
22             v=self.myPOST()
23         except Exception,e:
24             return "erro %s"%(e)
25         return v
以后所有的操作类都继承这个超类并且实现对应的myGET和myPOST方法(不用GET和POST方法)

1 class userreg(baseweb):
2     def myGET(self):
3         ...
这样出现异常以后可以直接在调试网页显示异常信息如下图
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值