开发者

sending two variables using httpresponse

开发者 https://www.devze.com 2023-03-09 10:32 出处:网络
foo = t.render(// blah blah //) bar = t1.render(// blah blah //) How can I send both th开发者_如何学JAVAese variables using HttpResponse. Using JSON, XML, CSV or any other format.I don\'t really und
foo = t.render(// blah blah //)
bar = t1.render(// blah blah //)

How can I send both th开发者_如何学JAVAese variables using HttpResponse.


Using JSON, XML, CSV or any other format.


I don't really understand what you want to achieve, a single view can return only one HttpResponse afaik, because a single request can only have one response. But if you want to have foo and bar (which I guess are rendered parts of a page) as variables in another view, you can add them to a regular render_to_reponse:

from django.shortcuts import render_to_response
from django.template import RequestContext

return render_to_response('template.html', { 'foo': foo, 'bar': bar }, context_instance=RequestContext(request)

I guess this could be usefull if you have ajax requests/responses, this way you have easy access to newly rendered parts of a page.


try this way

JSONObject json = new JSONObject();
json.put("foo",foo);
json.put("bar",bar);
json.put()... and so on....
0

精彩评论

暂无评论...
验证码 换一张
取 消