能不能抛异常来返回response?

1 view
Skip to first unread message

Chunlin Zhang

unread,
Sep 5, 2015, 10:23:30 AM9/5/15
to uli...@googlegroups.com
比如在权限检查的时候,当然是可以写decorator,不过 decorator很不直观,我到现在经常看decorator代码还是很晕,我就想能不能写个权限检查的函数,但函数返回值如果在view里如果要判断处理又很麻烦,所以我想能不能在检查函数里抛某个异常,异常里带 response,如果是这个异常uliweb捕获到就直接给客户端返回这个response就好了

我觉得这样挺方便的,limodou你看呢?

limodou

unread,
Sep 7, 2015, 8:31:44 AM9/7/15
to uliweb
可以写一个decorator,它来捕获异常,然后返回一个response

2015-09-05 22:23 GMT+08:00 Chunlin Zhang <zhangc...@gmail.com>:
比如在权限检查的时候,当然是可以写decorator,不过 decorator很不直观,我到现在经常看decorator代码还是很晕,我就想能不能写个权限检查的函数,但函数返回值如果在view里如果要判断处理又很麻烦,所以我想能不能在检查函数里抛某个异常,异常里带 response,如果是这个异常uliweb捕获到就直接给客户端返回这个response就好了

我觉得这样挺方便的,limodou你看呢?

--
-- ----
Project : https://github.com/limodou/uliweb
doc : http://limodou.github.com/uliweb-doc
---
You received this message because you are subscribed to the Google Groups "Uliweb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to uliweb+un...@googlegroups.com.
To post to this group, send email to uli...@googlegroups.com.
Visit this group at http://groups.google.com/group/uliweb.
To view this discussion on the web visit https://groups.google.com/d/msgid/uliweb/CAG2rzA%3D9zKNURzUKnx9GAxf4VmdVi%3DOk9DtuuKjGyDMY9HWV7Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.



--
I like python!
UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
UliWeb <<simple web framework>>: https://github.com/limodou/uliweb
My Blog: http://my.oschina.net/limodou

Chunlin Zhang

unread,
Sep 7, 2015, 9:47:17 AM9/7/15
to uli...@googlegroups.com
有道理,我怎么没想到呢,我考虑下这种方法怎么做比较好

Reply all
Reply to author
Forward
0 new messages