Updating the listing of an individual movie page
Now, let’s update the code to extract individual movie information from the database. We will need to, first, update the show function; second, update the movies.show
template; and third, add a custom CSS class.
Updating show function
In /movies/views.py
, add the following in bold:
… def show(request, id): movie = Movie.objects.get(id=id) template_data = {} template_data['title'] = movie.name template_data['movie'] = movie return render(request, 'movies/show.html', {'template_data': template_data})
Let’s explain the previous code:
- We use the
Movie.objects.get(id=id)
method to retrieve a specific movie based on itsid
. Remember...