当你做HttpResponse时,有没有人知道如何返回列表对象.
我试过了
HttpResponse(['a'.'b'])
Run Code Online (Sandbox Code Playgroud)
但这显然不起作用.
我也试过以下
return HttpResponse(Context(['a','b']),mimetype='text/plain')
Run Code Online (Sandbox Code Playgroud)
但这会返回一些我不想要的额外的东西
['a', 'b']{'False': False, 'None': None, 'True': True}
Run Code Online (Sandbox Code Playgroud)
我只想要它回来
['a', 'b']
Run Code Online (Sandbox Code Playgroud)
谢谢
这应该为你做
from django.utils import simplejson
json_stuff = simplejson.dumps({"list_of_jsonstuffs" : ["a", "b"]})
return HttpResponse(json_stuff, content_type ="application/json")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9434 次 |
| 最近记录: |