The case where course is not specified should return HttpResponseBadRequest, and you should check for that specifically rather than catch KeyError (which may have been raised within index_course).