-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 03/31/2014 05:11 AM, Chung WONG wrote:
> For example, there is a view returns a http exception to a request:
> @view_config(route_name='route', renderer='json',
> request_method='GET') def view(request): * return
> HTTPUnprocessableEntity(detail='details', comment='comment',
> body_template='body_template')*
>
> it returned a full html page *<html>* *<head>* *<title>422
> Unprocessable Entity</title>* *</head>* *<body>* *<h1>422
> Unprocessable Entity</h1>** body_template* *</body>* *</html>* is it
> possible to make the return as a JSON so that the frontend can extract
> the error message easily?
When you return a response object, pyramid bypasses the renderer. In your
case, you would need something like::
import json
@view_config(route_name='route', renderer='json', request_method='GET')
def view(request):
error = {'message': 'Could not process entity'}
return HTTPUnprocessableEntity(
body=json.dumps(error),
content_type='application/json')
Tres.
- --
===================================================================
Tres Seaver +1 540-429-0999 [email protected]
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iEYEARECAAYFAlM5jIkACgkQ+gerLs4ltQ7vXQCghToWo9ssPCoJrh4hZPjKi3uG
3eUAoM5ixHv6jt0p5JdvcxmZRGJcpIEd
=khsO
-----END PGP SIGNATURE-----
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.