Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Django Basics Django Templates Templates

Why do i need add dictionary to the views

def course_list(request): courses = Course.objects.all() return render(request, 'courses/course_list.html', {'courses': courses})

Why do we need {'courses': courses} in the render ?

1 Answer

Steven Parker
Steven Parker
231,236 Points

The optional 3rd argument to "render" is a context dictionary. It provides things that the template can reference, such as "courses" in this example. In the video, the template displays the "title" and "description" attributes of each item in the "courses" collection.