这种方式只能应用于从数据库中获取到的单条数据,例如models.Users.objects.get()获取到的数据

from django.forms.models import model_to_dictclass Index(VIew): def get(self, request): userObj = models.Users.objects.get(id = 1) userDict = model_to_dict(userObj) print(userDict) return HttpResponse('yes')

重点是导入的model_to_dict方法