- 我是Django新手,每当我执行json_data = JSONRenderer.render(serialized_student_data.data)这行代码时,它会给我类似TypeError的错误:render()缺少1个必需的位置参数:'数据'*
#以下是www.example.com中的代码models.py
class StudentModel(models.Model):
name = models.CharField(max_length=100, default='user')
roll_no = models.IntegerField(default=1)
city = models.CharField(max_length=100, default='Ahmedabad')
#以下是www.example.com中的代码serializers.py
class StudentSerializer(serializers.Serializer):
name = serializers.CharField(max_length=100)
roll_no = serializers.IntegerField()
city = serializers.CharField(max_length=100)
#以下是www.example.com中的代码views.py
def student_view(request):
student_object = StudentModel.objects.get(id=3)
serialized_student_data = StudentSerializer(student_object)
json_data = JSONRenderer.render(serialized_student_data.data)
return HttpResponse(json_data, content_type='application/json')
2条答案
按热度按时间vlf7wbxs1#
应该创建JSONRender对象而不是use类,代码将是,
n9vozmp42#