Django - How to get debugging information DatabaseError "current transaction canceled" on the Django error page?

When developing in my Django project, I get a DatabaseError that says:

the current transaction is aborted, commands are ignored until the end of the transaction block

I know that this is due to a bad PostgreSQL transaction without rollback, and the error in this bad transaction can be found in the PostgreSQL error log. However, I think it would be more convincing if this error is shown on the Django error page. Then you can directly see what the problem is.

So, is it possible to get these PostgreSQL errors on the Django error page? And if so, how?

+5
source share
1

, django.db.DatabaseError :

from django.db import DatabaseError

class DatabaseErrorMiddleware(object):
    def process_view(self, request, view, args, kwargs):
       try:
           view(request, *args, **kwargs)   
       except DatabaseError as err:
           import pdb; pdb.set_trace()
           # You can now fully inspect the `e` exception object and it context

, - , , , , .

+2

All Articles