Updating the movie listings page
Now, let’s update the code to extract movie information from the database. We will need to, first, update the index
function; second, update the movies.index
template; and third, add a custom CSS class.
Updating index function
In /movies/views.py
, add the following in bold:
from django.shortcuts import render from .models import Movie def index(request): template_data = {} template_data['title'] = 'Movies' template_data['movies'] = Movie.objects.all() return render(request, 'movies/index.html', {'template_data': template_data}) …
Let’s explain the previous code:
- We import the
Movie
model from themodels
file. We will use this model to access database information...