Django-views编写返回数据到前端
from django.shortcuts import render from django.http import JsonResponse import json # Create your views here. def home(request): # return render(request,'home.html') return render(request,'form.html') def menu1(request): return render(request,'menu1.html') def sendKafka(request): print(request.POST.get('name')) # 前端传的是from格式 print(json.loads(request.body)) # 前端传的是json格式数据体 return JsonResponse({"code":0,"message":"success!"}) def uploadFile(request): if request.method == 'POST': region = request.POST.get('region') if not region: return print(region) # print(json.loads(request.body)) return JsonResponse({"id":1}) return render(request,'upfile.html') def getselect(request): data = [{"gsid":"1","grade":"2"},{"gsid":"3","grade":"4"}] return JsonResponse({"se":data}) def table(request): if request.method == 'POST': # print('table post data:',json.loads(request.body)) data = [{ 'date': '2016-05-02', 'name': '王小虎', 'address': '上海市普陀区金沙江路 1518 弄', }, { 'date': '2016-05-04', 'name': '王小虎', 'address': '上海市普陀区金沙江路 1518 弄' }] for i in range(23): data.append({ 'date': '2016-05-04', 'name': '王小虎{}'.format(i), 'address': '上海市普陀区金沙江路 1518 弄' }) req = json.loads(request.body) print(req) if req.get('user'): data.append({'date': '2016-05-04', 'name': '王小虎{}'.format('999'), 'address': '上海市普陀区金沙江路 1518 弄'}) return JsonResponse({"se":data}) else: return render(request,'table2.html')
需要代写作业或者代做其他可以联系我:
承接基于python语言的各种系统开发