|
|
|
from django.shortcuts import render
|
|
|
|
|
|
|
|
# Create your views here.
|
|
|
|
from django.http import JsonResponse
|
|
|
|
from Student.models import Student
|
|
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
|
|
from django.http import QueryDict
|
|
|
|
|
|
|
|
|
|
|
|
def delete_student(request):
|
|
|
|
sid = request.GET.get("sid")
|
|
|
|
info = Student.objects.filter(sid=sid).delete()
|
|
|
|
response = {"code": 200, "message": "删除成功!", "data": info}
|
|
|
|
return JsonResponse(response)
|
|
|
|
|
|
|
|
|
|
|
|
@csrf_exempt
|
|
|
|
def studnets(request):
|
|
|
|
if request.method == "POST":
|
|
|
|
student = Student()
|
|
|
|
student.s_username = request.POST.get("s_username")
|
|
|
|
student.s_password = request.POST.get("s_password")
|
|
|
|
student.s_name = request.POST.get("s_name")
|
|
|
|
student.s_sex = request.POST.get("s_sex")
|
|
|
|
student.s_grade = request.POST.get("s_grade")
|
|
|
|
student.s_class_name = request.POST.get("s_class_name")
|
|
|
|
student.s_major = request.POST.get("s_major")
|
|
|
|
student.save()
|
|
|
|
response = {"code": 200, "message": "添加成功!", "data": student.to_dict()}
|
|
|
|
return JsonResponse(response)
|
|
|
|
elif request.method == "GET":
|
|
|
|
student_list = Student.objects.all()
|
|
|
|
response_json = {"code": 200, "message": "success", "data": []}
|
|
|
|
for student in student_list:
|
|
|
|
response_json["data"].append(student.to_dict())
|
|
|
|
return JsonResponse(response_json)
|
|
|
|
|