Object of type 'QuerySet' is not JSON serializable

在做前端ajax异步加载数据库数据的时候出现Object of type ‘QuerySet’ is not JSON serializable,大概意思是’QuerySet’对象不是json数据类型。
views.py

from django.shortcuts import render, redirect, reverse
from django.http import JsonResponse
from .models import Student

def index(request):
	return render(request, 'index.html')

def ajax_handle(request):
    students = Student.objects.all()
    data = {
        'students': students
    }
    return JsonResponse(data)

urls.py

from django.urls import path, include
from . import views

app_name = 'new'

urlpatterns = [
    path('index/', views.index, name='index'),
    path('ajax_handle/', views.ajax_handle, name='ajax_handle'),
]

index.html


    
                    
                    

你可能感兴趣的:(django,mysql,python,编程)