On Oct 17, 3:51 pm, Łukasz Rekucki <lreku...@gmail.com> wrote:
> > Currently, you can override only how successful responses are > rendered. I'm going to try to work on this on my branch, but I have a > small problem: In number of places, views raise Http404 which then get > rendered by the default 404 handler (which will render HTML, which is > useless for an AJAX view). I don't currently see an easy way, to > override this on a per-view basis with just a mixin. I could catch > Http404 exception, but it won't trigger middleware handling as it > normally does. Any suggestions ? > > -- > Łukasz Rekucki One option might be to catch the Http404 in dispatch(), and then call a "render_not_found" method if it is defined, and raise the exception again if it is not: def dispatch(self): try: ... return handler(response, *args, **kwargs) except Http404: if hasattr(self, "render_not_found"): return self.render_not_found(response, *args, **kwargs) else: raise render_not_found() could be optionally implemented by the render response mixin, or left out entirely for standard 404 handling. Data- oriented mixins could choose to implement it to provide a non-html error response. -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-develop...@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.