[Fixed]-Django exception line number logging through middleware

1👍

I had to do this recently writing ExceptBot. That links to the source repo.

The relevant code is:

import traceback


class ExceptBotMiddleware:

    def process_exception(self, request, exception):
        # Get the current stack trace
        current_traceback = traceback.extract_stack()
        stack = current_traceback[-1]
        # getting the line number
        line_number = stack.lineno

Leave a comment