You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
1.2 KiB
33 lines
1.2 KiB
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
|
|
|
|
@csrf_exempt
|
|
def studnets(request):
|
|
if request.method == "POST":
|
|
student = Student()
|
|
student.username = request.POST.get("username")
|
|
student.password = request.POST.get("password")
|
|
student.s_name = request.POST.get("s_name")
|
|
student.sex = request.POST.get("sex")
|
|
student.grade = int(request.POST.get("grade"))
|
|
print(student.grade)
|
|
student.class_name = request.POST.get("class_name")
|
|
student.major = request.POST.get("major")
|
|
student.sid = request.POST.get("sid")
|
|
print(student.to_dict())
|
|
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)
|
|
|
|
|