djangopythonanywhere

Simplest way to get Django errors emailed to


I have a Django Application hosted on Python Anywhere with a PostGre back end.

Is there anyway I can get the errors that are normally added to the error log to sent to my email, so I can be quickly notified of error.

I am familiar with writing simple middleware, but i don't understand Django well enough to know how to capture the errors that go to error-log file.


Solution

  • Django already provides a feature for sending emails on errors. You can set the "ADMINS" flag in the settings for notifying specific emails when an error occurs.

    ADMINS = [
        ("abc", "abc@gmail.com"),
    ]
    

    https://docs.djangoproject.com/en/5.0/ref/settings/#admins
    For this, you need have your SMTP settings configured in django, and DEBUG to be false in deployment. It will notify you only if a 500 INTERNAL SERVER occurs with the traceback log of the error.