def request_wants_json():
 if flask.request.base_url.endswith('.json'):
  return True
 best = flask.request.accept_mimetypes.best_match(['application/json', 'text/html'])
 return ((best == 'application/json') and (flask.request.accept_mimetypes[best] > flask.request.accept_mimetypes['text/html']))

def request_wants_json ( ) : if flask . request . base_url . endswith ( '.json' ) : return True best = flask . request . accept_mimetypes . best_match ( [ 'application/json' , 'text/html' ] ) return ( ( best == 'application/json' ) and ( flask . request . accept_mimetypes [ best ] > flask . request . accept_mimetypes [ 'text/html' ] ) )
we only accept json if the quality of json is greater than the quality of text/html because text/html is preferred to support browsers that accept on */* .