search

Home  >  Q&A  >  body text

python - How does Django get the values ​​from the database and put them together for output

Code

def gettem(request):
    if(request.method=='GET'):
        tem = Iotdata.objects.values_list('tem', flat=True)[0:10]
        print(tem)
        return HttpResponse(tem)

Command line print screenshot

Obtained through request, found that there is no output like [32,32,32]

PHP中文网PHP中文网2817 days ago836

reply all(1)I'll reply

  • 某草草

    某草草2017-06-12 09:29:53

    After Django version 1.7, you can use JsonResponse instead of HttpResponse to return JSON format. Since your tem is a QuerySet object, a plain text string is returned directly after HttpResponse processing, so the result set is spliced ​​together.

    reply
    0
  • Cancelreply