Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Django ORM Total Control Mind your Ps and Qs

How search is working?

I have not seen the search function in any of the previous videos , and what does " term = request.GET.get('q') " do.

1 Answer

Quite a late answer, but maybe this will help someone:

When there is a form with method="GET all input fields will be added to URL of the submit request. So <input type="search" name="q"> means "q=Android" will be added to the next URL.

When handling the request request.GET returns a dictionary of all the URL parameters of GET request: so /courses/search/?q=Android will return {'q':['Android']}`

and .get('q') gets the value for the 'q'.