使用httpresponse发送两个变量

时间:2011-05-30 11:34:36

标签: ajax django

foo = t.render(// blah blah //)
bar = t1.render(// blah blah //)

如何使用HttpResponse.

发送这两个变量

3 个答案:

答案 0 :(得分:2)

使用JSON,XML,CSV或任何其他格式。

答案 1 :(得分:1)

我真的不明白你想要实现什么,单个视图只能返回一个HttpResponse afaik,因为一个请求只能有一个响应。但是如果你想让foo和bar(我猜它是渲染页面的一部分)作为另一个视图中的变量,你可以将它们添加到常规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)

我想如果您有ajax请求/响应,这可能很有用,这样您就可以轻松访问页面的新渲染部分。

答案 2 :(得分:0)

试试这种方式

JSONObject json = new JSONObject();
json.put("foo",foo);
json.put("bar",bar);
json.put()... and so on....
相关问题