Django python clarification request

RE: Python course, django section: 11- Templates

I do not understand the interaction between the views.py and index.html

My code for views.py was:
def index(request1):
movies1 = Movie.objects.all()
return render(request1, ‘index1.html’, {‘movies’: movies1})

My code for index1.html was:

{% for movie in movies1 %} {{ movie.title }} {{ movie.genre }} {{ movie.number_in_stock }} {{ movie.daily_rate }} {% endfor %}

With the above code, I see no database results. However, when I change one line I get database results:
{% for movie in movies %}
How is this possible?

In your views file you are storing the ‘movies1’ into the ‘movies’ key inside the dictionary. Then in the ‘index1.html’ you have to use the key (ie. movies).

I hope this clears it up. If you have any further questions then I’m more than happy to answer them.

P.S A pro tip is to create a dictionary called ‘context’, then use ‘context’ in the return statement.

def index(request):
    movies = Movie.objects.all()
    customers = Customers.objects.all()
    theatres = Theatres.objects.all()
    
    context = {
        'movies': movies,
        'customers': customers,
        'theatres': theatres,
    }
    return render(request, ‘index1.html’, context)