Django项目文件梳理
django学习文档
Django 文档 | Django 文档 | Django (djangoproject.com)
前端核心代码
import qs from 'querystring' import fetch from '@system.fetch' export default { data:{ winfo:"", }, onClick(){ fetch.fetch({ url:'http://192.168.2.105:8080/', data:qs.stringify({'id':'1'}), responseType:"json", method:"POST", success:(resp)=>{ this.winfo = resp.data; console.log("返回数据:"+this.winfo) }, fail:(resp)=>{ this.winfo = resp.data; console.log("获取数据失败:"+this.winfo+resp) } }); }, }
后端核心代码
from django.shortcuts import render from django.http import HttpResponse from django.shortcuts import render from student import models from rest_framework.views import APIView class AppReq1(APIView): def post(self, request): re = models.Students.objects.filter(Age=20)//注意re不能写成request,会报错 arr = [] for i in re: content = {'姓名': i.Name, '邮箱': i.Email, '年龄': i.Age} arr.append(content) print(arr) print(type(arr)) ID = request.data.get('id') # username = request.data.get('username') # password = request.data.get('password') print(ID) # print(username) # print(password) return HttpResponse(arr)
个人总结:有点难学习,还需要认真学习总结练习