python - How does Django get the values ​​from the database and put them together for output
PHP中文网
PHP中文网 2017-06-12 09:27:53
0
1
765

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中文网

认证0级讲师

reply all(1)
某草草

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!