Skip to content

Instantly share code, notes, and snippets.

@lxneng
Created December 7, 2016 02:21
Show Gist options
  • Save lxneng/37010d3ef007a598763be583483bd509 to your computer and use it in GitHub Desktop.
Save lxneng/37010d3ef007a598763be583483bd509 to your computer and use it in GitHub Desktop.
quick trick for changing exceptions to json
@view_config(context=HTTPException)
def exception_view__upgrade(exc, request):
"""if we end with .json, serve json."""
if (request.path[-5:]).lower() == '.json':
request.environ['HTTP_ACCEPT'] = "application/json"
return exc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment