Re: override render_to_response

2009-03-17 Thread matehat

I think the closest you could get to a painless implementation of what
you need, for existing apps, could be to create a method named
something like "render_to_json_response", that behave the way you want
and have the appropriate "views" modules in each app import it as
"render_to_response" (indeed commenting out the original import
statements).
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: override render_to_response

2009-03-16 Thread Malcolm Tredinnick

On Mon, 2009-03-16 at 18:34 -0700, Preston Timmons wrote:
> I am wondering if render_to_response is really the proper function you
> are looking for.
> 
> For instance, here is a simple view that returns json using
> HttpResponse without need of a template:

He was wanting to hijack the output from existing views in other
applications for some reason, from what I gathered.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: override render_to_response

2009-03-16 Thread Preston Timmons

I am wondering if render_to_response is really the proper function you
are looking for.

For instance, here is a simple view that returns json using
HttpResponse without need of a template:

import simplejson
from django.http import HttpResponse
def output_json(request):
data = [
dict(name='joe', weight=165),
dict(name='roger', weight=130),
]
return HttpResponse(simplejson.dumps(data), mimetype="application/
json")


More docs on the HttpResponse is available here:
http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponse.__init__


Preston
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: override render_to_response

2009-03-16 Thread Malcolm Tredinnick

On Mon, 2009-03-16 at 20:05 -0400, Malinka Rellikwodahs wrote:
[...]
> Unless I'm mistaken it should be fairly simple in this case to create
> your own set of templates for each of the django apps you're using and
> then have them output the data you need as json text instead of as
> html

Ooh ... that's a clever idea. Could even be done with a simple template
tag, rendering everything in the context to json results.

For the original poster: If youdo this, don't forget to use middleware
to change the content type on the response.

Regards,
Malcolm



--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: override render_to_response

2009-03-16 Thread Malinka Rellikwodahs

On Mon, Mar 16, 2009 at 12:42, a b <dolittle...@gmail.com> wrote:
> Hi,
>
> I'm building a one page app with no page refresh.
> All the content is loaded as JSON dynamically and the UI is built using
> javascript.
>
> I'm using external django apps and I need them to send back the context dict
> as JSON instead
> of rendering the html template.
>
> Is it possible to override render_to_response so all the apps using it will
> respond with JSON without
> actually touching the apps code? I don't want to create a middleware that
> will modify the response because
> then I have the overhead of rendering the html template.

Unless I'm mistaken it should be fairly simple in this case to create
your own set of templates for each of the django apps you're using and
then have them output the data you need as json text instead of as
html

> Thanks
>
> >
>

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: override render_to_response

2009-03-16 Thread Malcolm Tredinnick

On Mon, 2009-03-16 at 18:42 +0200, a b wrote:
> Hi,
> 
> I'm building a one page app with no page refresh.
> All the content is loaded as JSON dynamically and the UI is built
> using javascript.
> 
> I'm using external django apps and I need them to send back the
> context dict as JSON instead
> of rendering the html template.
> 
> Is it possible to override render_to_response so all the apps using it
> will respond with JSON without
> actually touching the apps code?

Not really, no. Monkey-patching like that is generally discouraged, in
any case.

Regards,
Malcolm




--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



override render_to_response

2009-03-16 Thread a b
Hi,

I'm building a one page app with no page refresh.
All the content is loaded as JSON dynamically and the UI is built using
javascript.

I'm using external django apps and I need them to send back the context dict
as JSON instead
of rendering the html template.

Is it possible to override render_to_response so all the apps using it will
respond with JSON without
actually touching the apps code? I don't want to create a middleware that
will modify the response because
then I have the overhead of rendering the html template.

Thanks

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---