-3

Suppose I want to know what the array contains, like JS concole.log() or php var_dump

def showArticle(request):
     articles = Article.objects.all()
     return render(request, 'article.html', {'articles': articles})

My template:

<pre>
    {{ articles }}
</pre>

It shows:

<QuerySet [<Article: Article object>]>

If I use

{% for article in articles %}
    {{ article }}
{% endfor %}

It will show the same

    Article object
    Article object
    Article object

and if I want show request.

def printRequest(request):
     req = str(request)
     print(request)

it prints only:

<WSGIRequest: GET '/'>
miradulo
  • 28,857
  • 6
  • 80
  • 93
val123
  • 3
  • 5

1 Answers1

1

Try

{% for article in articles %}
    {{ article.values }}
{% endfor %}

But a debugger is really what you want for this kind of stuff. Or even just printing to the console.

Printing Objects in Django

Rob L
  • 3,634
  • 2
  • 19
  • 38