On Tue, Feb 14, 2012 at 11:14 AM, Kevin <kveron...@gmail.com> wrote:
> Hello everyone,
>
>  Before I go ahead and build a simple middleware for this myself, I
> would like to know if such a middleware already exists in the wild, so
> that I can prevent re-inventing the wheel.  Here's an example, if
> nobody is following what the subject actually means:
>

Why would you do it as middleware? This would mean two things:

1) The middleware will have to do lots of nasty isinstance/other type checking.
2) You break the contract of what a view is - a view is a callable
returning a response. Your 'view' functions will just be random
functions returning arbitrary objects, which may or may not be
translated into a response by middleware. Hacky.

Instead, simply subclass HttpResponse, and make it do what you want it
to do. As an example, as your specified use case was to simplify
generating JSON responses, I give you JSONResponse:

http://djangosnippets.org/snippets/154/

Cheers

Tom

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to