您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Django返回json数据用法示例

2024/2/27 20:31:43发布11次查看
本文实例讲述了django返回json数据用法。分享给大家供大家参考,具体如下:
1、前端。jquery发送get请求,并解析json数据。getjson方法可参考这里。
url = "http://example/?question=" + question + "&rand=" + math.random(); $.getjson(url, function(json){ answer = json.answer; alert(answer); });
2、后端。django接收get请求并返回json数据。
from django.http import httpresponse from django.utils import simplejson if request.method == 'get' and 'question' in request.get: question = request.get['question'] print(question) data = {"answer": "answer"} #ensure_ascii=false用于处理中文 return httpresponse(simplejson.dumps(data, ensure_ascii=false))
更多django返回json数据用法示例。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product