On 31/03/14 08:12, Chung WONG wrote:
Thanks Mariano.

Do you mean sth like:
     def view(request):
*        request.response.content_type='application/json'*
*        return HTTPUnprocessableEntity(detail='details',
comment='comment', body_template='body_template')*
*
*
Unfortunately, it still returned a HTML Page.


You should set it in your HTTPUnprocessableEntity object (I believe it is an instance of the Response).

On Monday, March 31, 2014 9:38:19 PM UTC+11, Mariano Mara wrote:



    On 31/03/14 06:11, 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?
     >
     > thanks
     >
    Try setting the corresponding content_type in the Response object:
    application/json

    Mariano

--
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]
<mailto:[email protected]>.
To post to this group, send email to [email protected]
<mailto:[email protected]>.
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.

--
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.

Reply via email to