How Django2.0 prints data structures, similar to PHP's print_r ()

for example, I defined a method in the view file.

views.py

from django.shortcuts import render
from django.http import HttpResponse

from . import models

def index(request):

    datas = models.Test.objects.get(id=1)
    
    print(datas)  -sharp
    return render(request,"polls/index.html",{"data":datas})

how to print the returned data structure to the page with Django?

Aug.04,2021

data is already plural, so don't use datas. In addition, models.Test.objects.get (id=1)
is used here. If it is found, an instance of model will be returned, and if it cannot be found, an exception will be thrown. This exception may cause you not to print out
the information printed during normal operation is Test object
conclusion:
look at the data structure as print (datas.__dict__)

.
Menu