Difference between model_name.objects.all() and model_name.objects.last()

Hello there. I am a newbie to Django. I am currently stuck at a point where the objects from one of my models dont appear in the website with the command : variable_name = model_name.objects.all().
but when I use “model_name.objects.last()” they do appear. So, what is the difference between these two?

variable_name = model_name.objects.all()

This returns a QuerySet. It’s part of the collection of QuerySet methods that return new QuerySets.


This is part of the collection of methods that do not return QuerySets.

It’s hard to understand exactly what it is you want to do based on the information you’ve provided. If you’re trying to refer to your data from a template, it’s likely that you’ll want to loop over the QuerySet you get when using the .all() method.

So instead of

<p>{{ my_obj.name }}</p>

You’d want to use

{% for obj in my_queryset_of_objects %}
    <p>{{ obj.name }}</p>
{% endfor %}

If you haven’t done any tutorials yet, you might want to try
https://www.djangoproject.com/start/ (suitable if you already know a fair bit of programming/Python/how the web works)
https://tutorial.djangogirls.org/en/ (suitable if you don’t have much experience programming/using Python)