[Answered ]-Show Django errors on console rather than Web Browser

1👍

I know that’s not the answer to the question, but it is the solution to the proposed problem. In Google Chrome, if you open the Developer Tools (Ctrl+Shift+J), you can go to the Network tab, click on the request with error (it will be red), and then click on the Response tab, in the panel that opened by the right. There, you will be able to see the errors for POST, PUT and DELETE.

enter image description here

1👍

In your views.py you just have to print Response.data with serializer’s errors and Python web server will show the details of failure. Like in this example:

def post(self, request, format=None):
    serializer = DataSerializer(data=request.data)
    if serializer.is_valid():
        serializer.save()
        return Response(serializer.data, status=status.HTTP_201_CREATED)
    else:
        error = Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
        print(error.data)
    return error

0👍

In settings.py, set DEBUG=True to make Django show the whole error information in the web response.

With DEBUG=False you have to manually print the error to console using print or export it to a log with some log tool.

👤dsob

Leave a comment