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
Simon Amz
4,606 PointsHow to identify args and kwargs?
Hi there,
def search(request):
term = request.GET.get('q')
courses = models.Course.objects.filter(Q(title__icontains=term)|Q(description__icontains=term), published=True)
return render(request, 'courses/course_list.html', {
'courses': courses
})
In the previous code, let's assume that:
A = 'published=True' ; B = 'Q(title_icontains=term)|Q(description_icontains=term)'
In the video, Kenneth explained that we cannot put A before B in a filter, because A is kwargs whereas B is args.
I know that args must be declare before kwargs but I don't understand why A is kwargs and B is args.
Thanks for your feedback
2 Answers
Chris Freeman
Treehouse Moderator 68,468 PointsThe simplest answer is the presence of published=. To be a kwarg, that is, a keyword argument, a keyword (or parameter name) must be provided. In this case, the keyword is "published".
When a keyword is not present, the argument is a direct object reference or the object itself. In the case, B is a Q object
Post back if you have more questions. Good luck!!
Simon Amz
4,606 Pointsthanks!