django HttpResponse的用法
生活随笔
收集整理的這篇文章主要介紹了
django HttpResponse的用法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、傳json字典
def back_json(rquest):#JsonResponse父類是HttpResponse,原碼里調用了json.dumps()from django.http import JsonResponseback_msg = {'name':name,'age':123}return JsonResponse(back_msg)二、傳列表
def back_json(rquest):#JsonResponse父類是HttpResponse,原碼里調用了json.dumps()from django.http import JsonResponseback_list = [1,2,3]#JsonResponse默認傳字典,傳列表的話需要指定safe=Falsereturn JsonResponse(back_list,safe=False)?
轉載于:https://www.cnblogs.com/di2wu/p/10068528.html
總結
以上是生活随笔為你收集整理的django HttpResponse的用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 招才猫直聘(百度校园招聘)
- 下一篇: 机器学习套路三步走