Hi, On Mon, Jul 27, 2009 at 09:50:31PM +0400, Ivan Sagalaev wrote: > > Marc Fargas wrote: > > You could write an Exception middleware that takes care of processing > > your "special" exception. Bu anyway, note that you are willing is to > > give "response" so the right thing to do would be returning a response > > object > > The latter is not very convenient. Often the code that makes a decision > about forbidding something is buried deep into model layer and can't > easily return an HttpResponse. So I believe that making a special > exception and converting it into an HttpResponseForbidden in a > middleware is a good way to do this in current Django code. But I can > really see the value of making it a part of Django even if just for the > sake of consistency with Http404. BTW other HTTP errors in my practice > don't work by this pattern so I don't propose making an exception for > everything >= 400.
But your model code shouldn't have HTTP-related bits buried in it. That's a layering violation. That code should raise a more generic exception that your view code converts to an HTTP response. -Forest -- Forest Bond http://www.alittletooquiet.net http://www.pytagsfs.org
signature.asc
Description: Digital signature
