[Fixed]-How do I get django runserver to show me DeprecationWarnings and other useful messages?

1👍

The runserver command ignores the verbosity option: https://code.djangoproject.com/ticket/15132

I’d recommend setting up a logger and directing the output to stderr: https://docs.djangoproject.com/en/1.3/topics/logging/

For example:

import logging
logger = logging.getLogger('django')   # Django's catch-all logger
hdlr = logging.StreamHandler()   # Logs to stderr by default
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
logger.addHandler(hdlr) 
logger.setLevel(logging.WARNING)

28👍

Python 2.7 disables the display of DeprecationWarning by default

To re-enable it, set environment variable PYTHONWARNINGS to “d”:

export PYTHONWARNINGS="d"; ./manage.py runserver
👤chrisv

4👍

To have your development server and your tests fail for DeprecationWarnings in order to locate and fix them, you can convert them to errors by adding

if settings.DEBUG:
    import warnings
    warnings.simplefilter('error', DeprecationWarning)
# these are less urgent but could also be enabled
#   warnings.simplefilter('error', PendingDeprecationWarning)

to your top-level urls.py.

I prefer this approach because it fails in tests and lets me locate the deprecated code one by one in an automated fashion.

Leave a comment