So I'm trying to port some old Pylons code to Pyramid, and I'd like to be able to improve on the Auth setup - specifically support better RBAC, and Pyramid has good support for this. However, I'd like to offer unauthorised users better info when they try illegal pages:
"Sorry, in order to view [page] you ([user]) need [group] privileges - please contact [admin]"
However I don't see how that's practical in Pyramid - I can do stuff in the forbidden_view_config page, however I can't easily find all the info needed from the page which was attempted - is it possible to get the exception or similar with the actual reason why permission was not granted?
context
is one place to get the object. The request object itself should have all the other bits you need. Unless, of course, you redirect to another page. – Steve Piercyreturn HTTPFound(location=request.route_url("home"))
, for example. You shouldraise HTTPForbidden()
. You can customize that however you like. Pyramid docs and the Community Cookbook have examples. – Steve Piercy