def ensure_valid_usage_key(view_func):
 @wraps(view_func)
 def inner(request, *args, **kwargs):
  usage_key = kwargs.get('usage_key_string')
  if (usage_key is not None):
   try:
    UsageKey.from_string(usage_key)
   except InvalidKeyError:
    raise Http404
  response = view_func(request, *args, **kwargs)
  return response
 return inner

def ensure_valid_usage_key ( view_func ) : @ wraps ( view_func ) def inner ( request , * args , ** kwargs ) : usage_key = kwargs . get ( 'usage_key_string' ) if ( usage_key is not None ) : try : UsageKey . from_string ( usage_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 usage_key_string .