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

Sahar Nasiri
Sahar Nasiri
7,454 Points

The context dictionary

Why did Kenneth say this is optional!? When I erase it all the courses will be gone from the web page! Besides, it seems that we are passing the courses to the template module because it is the only place where we are using both courses.html file and courses objects.

1 Answer

David Lin
David Lin
35,864 Points

The context dictionary is an optional parameter, since you can have a template that doesn't need any context to complete its contents (e.g. the home.html page example with a simple "Welcome" that Kenneth made in the last part of the video). However, in the course_list example, you do need the context to pass through the required courses data structure which is necessary to fill out the contents of the template.

So, the context parameter is "optional" in the sense that it's not required to be passed through to the template, but of course, if it's necessary for your specific template, then you definitely should.