2010/5/13 Oskar <[email protected]>:
> Hey!
>
> I've been using web.seeother() without the 'raise' at the end of some
> POST functions, and it works as I expected. But I've seen it be used
> with a 'raise' in front of it, and I'm curious as to why it is often
> used like that. Is it just to break out of the function? Couldn't
> 'web.seeother(); return' or even 'return web.seeother()' be used as
> well? I'm a little confused because raise is typically used for
> exceptions but one may call web.seeother() even where there is nothing
> exceptionally going on.
It makes code a lot simpler. Try doing the following without
exceptions and you will understand the simplicity it brings.
class edit:
def GET(self):
verify_logged_in()
return render.edit()
def can_write():
verify_logged_in()
user = get_user()
if not user.is_admin():
raise web.ok(render.permission_denied())
def verify_logged_in():
user = get_user()
if user is None:
raise web.seeother("/account/login")
The reason "return web.seeother()" also works is because the status
was set when the exception was created and not when the exception is
caught. I think that is a wrong behavior and will be fixed in future
releases.
Anand
--
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.