On Mon, 2007-11-12 at 23:29 -0800, eXt wrote: > Hi! > > I'd like to know if there is any method to handle 403 errors and > display pretty error pages for them. > > I need to handle some errors raised by Admin (raised when a user > clicks an add symbol but doesn't have the permission to add a new > object). > > In the Admin code I have found add_view function of ModelAdmin which > does: > > if not self.has_add_permission(request): > raise PermissionDenied > > Then there is django.core.handlers.base.py and: > (...) > except exceptions.PermissionDenied: > return http.HttpResponseForbidden('<h1>Permission denied</ > h1>') > > which causes me to receive ugly untranslated "Permission denied" page. > Django has a handler for 404 is it possible to write one for 403?
I would write a response middleware that inspects the response for respnsoe.status == 404 and then goes from there. The only reason 404 errors are handled slightly specially in Django is because you can raise an Http404 *exception* and that gets caught by the request handling loop. No other status codes (except for uncaught exceptions) are triggered by exceptions. In all these cases, you just return an HttpResponse class with the right status code set. Malcolm -- Everything is _not_ based on faith... take my word for it. http://www.pointy-stick.com/blog/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---