Working on learning Django, and at the moment (trying to) have a template that creates a list of “robots” that I’ve created. I’m not looking for help on the specific problem — I’m trying to figure it out by myself — but I would like to know if I can figure out where I’m failing.
The lookup looks like this. Currently, in the template, it returns nothing (and there are definitely two “robots” in the database:
<p>Robotz!</p>
{% for bot in robots.all %}
<p>{{bot.name}} //{{bot.serialnumber}}</p>
{% endfor %}
<p>And that's a list of robots.</p>
What I don’t know is whether…
– “robots.all” is looking in the wrong place in the second line,
– “for bot in” is bad syntax in the second line,
or
– “bot.name” and “bot.serialnumber” are bad values to print in the third line.
Right now, the template returns nothing: it goes straight from “Robotz!” to “And that’s a list of robots.” on the served HTML page. Inspect Element in Chrome gives me nothing between those two lines.
Is there a way to find out what I’m doing wrong? Not specific to this instance, but so I can see whether I’m looking in the wrong place, or putting out the wrong output.
Again, I want to figure out how to do this by myself, but I’m looking for tools that can help me know where I’m screwing this up: is there something like Inspect Element that would work for Django, so I can see what lines are/aren’t seeking and returning data like I can see which CSS lines are and aren’t active using Inspect Element?
django-debug-toolbar would help you a lot in this case. It shows you all queries that were executed. It doesn’t show you queries line by line, but it’ll give you general idea what’s happening in your application.