def ensure_valid_course_key(view_func):
 @wraps(view_func)
 def inner(request, *args, **kwargs):
  course_key = (kwargs.get('course_key_string') or kwargs.get('course_id'))
  if (course_key is not None):
   try:
    CourseKey.from_string(course_key)
   except InvalidKeyError:
    raise Http404
  response = view_func(request, *args, **kwargs)
  return response
 return inner

def ensure_valid_course_key ( view_func ) : @ wraps ( view_func ) def inner ( request , * args , ** kwargs ) : course_key = ( kwargs . get ( 'course_key_string' ) or kwargs . get ( 'course_id' ) ) if ( course_key is not None ) : try : CourseKey . from_string ( course_key ) except InvalidKeyError : raise Http404 response = view_func ( request , * args , ** kwargs ) return response return inner
this decorator should only be used with views which have argument course_key_string or course_id .