Django: how to get stack traces for runtime warnings Django: how to get stack traces for runtime warnings django django

Django: how to get stack traces for runtime warnings


From the docs at: https://docs.djangoproject.com/en/1.10/topics/i18n/timezones/#code

During development, you can turn such warnings into exceptions and get a traceback by adding the following to your settings file:

import warningswarnings.filterwarnings(    'error', r"DateTimeField .* received a naive datetime",    RuntimeWarning, r'django\.db\.models\.fields')


You can implement your a log formatter and put trace back for warning messages in the logs using traceback.print_exception().

Refer to Fomatter docs at FormatException

You can also refer this, How do I use Django's logger to log a traceback when I tell it to?


This means that you enabled timezone support in django; but you passed it a datetime object that doesn't have any time zone information attached to it.

If you want django's timezone support, then datetime objects used should be timezone aware.

The documentation on timezone support provides a way to turn your datetime objects into those with timzeones.