fvb : function views
cvb : class views
一、fvb
HttpResponse 返回字符串的话用它
JsonResponse 返回json的话,直接给他传个字典
from django.http import HttpResponse,JsonResponse
from .models import Student
# fvb function views
def stu(request):
if request.method == 'GET':
data = {"msg": "查询成功"}
elif request.method == 'POST':
data = {"msg": "成功"}
elif request.method == 'PUT':
data = {"msg": "成功"}
elif request.method == 'DELETE':
data = {"msg": "成功"}
else:
data = {"msg": "成功"}
return JsonResponse(data,json_dumps_params={"ensure_ascii":False})