Wie deaktivieren Sie die Rückkehr von HTML-Fehler-Seite mit django rest framework?

Wenn ich einen Fehler außerhalb der libs von DRF, django zurück senden den HTML-Code der Fehler statt des richtigen Fehler-Reaktion die Verwendung von DRF.

Beispiel:

@api_view(['POST'])
@permission_classes((IsAuthenticated,))
def downloadData(request):
    print request.POST['tables']

Rückkehr Ausnahme MultiValueDictKeyError: "'tables'". Und wieder die volle HTML. Wie bekommen nur die Fehler einer JSON?

P. D:

Dies ist der Letzte code:

@api_view(['GET', 'POST'])
def process_exception(request, exception):
    # response = json.dumps({'status': status.HTTP_500_INTERNAL_SERVER_ERROR,
    #                        'message': str(exception)})
    # return HttpResponse(response,
    #                     content_type='application/json; charset=utf-8')
    return Response({
        'error': True,
        'content': unicode(exception)},
        status=status.HTTP_500_INTERNAL_SERVER_ERROR
    )


class ExceptionMiddleware(object):
    def process_exception(self, request, exception):
        # response = json.dumps({'status': status.HTTP_500_INTERNAL_SERVER_ERROR,
        #                        'message': str(exception)})
        # return HttpResponse(response,
        #                     content_type='application/json; charset=utf-8')
        print exception
        return process_exception(request, exception)
InformationsquelleAutor mamcx | 2014-01-13
Schreibe einen Kommentar