I am creating a web2py application and I am using Auth for login.
Some of my controllers have functions that should be publicly accessible,
but may sometimes attempt to access data that requires authorisation, in
which case I raise HTTP 401. If the user is already logged in, it raises a
403.
I would like to use routes_onerror to make it so that if a 401 error is
raised, the user will be redirected to the login page.
The directory structure is
web2py
|_ applications
|_ APPNAME
|_ controllers, models, views, etc.
In the web2py directory, I have placed routes.py, which is the renamed
routes.parametric.example.py file that comes in the web2py/examples
directory.
In the APPNAME directory, I have placed routes.py, with contents:
routes_onerror = [
('*/401', '/APPNAME/default/handle_401')
]
In my default.py controller, this is the handle_401 function:
def handle_401():
redirect(auth.settings.login_url)
I have pressed 'Reload routes' on the web2py admin page.
When there is a 401 error, it still just displays displays the error
message passed alongside the raise, rather than redirecting.
Have I done something wrong to set it up? Is there anything I can do to
diagnose why it isn't working?
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.