How to suppress the deprecation warnings in Django?
Question: Every time I'm using the `django-admin` command — even on TAB–completion — it
throws a `RemovedInDjango19Warning` (and a lot more if I use the _test_
command). How can I suppress those warnings?

I'm using Django 1.8 with Python 3.4 (in a virtual environment).

As far as I can tell, all those warnings come from libraries not from my code,
here are some examples:

  * `…/lib/python3.4/importlib/_bootstrap.py:321: RemovedInDjango19Warning: django.contrib.contenttypes.generic is deprecated and will be removed in Django 1.9. Its contents have been moved to the fields, forms, and admin submodules of django.contrib.contenttypes. return f(*args, **kwds)`

  * `…/lib/python3.4/site-packages/django/contrib/admin/util.py:7: RemovedInDjango19Warning: The django.contrib.admin.util module has been renamed. Use django.contrib.admin.utils instead. "Use django.contrib.admin.utils instead.", RemovedInDjango19Warning)`

  * `…/lib/python3.4/site-packages/django/templatetags/future.py:25: RemovedInDjango19Warning: Loading the ``url`` tag from the ``future`` library is deprecated and will be removed in Django 1.9. Use the default ``url`` tag instead. RemovedInDjango19Warning)`


Answer: Adding a logging filter to settings.py can suppress these console warnings (at
least for manage.py commands in Django 1.7, Python 3.4).

A filter can selectively suppress warnings. The following code creates a new
"suppress_deprecated" filter for the console and appends it to the default
logging filters. Add this block to settings.py to configure the LOGGING
variable:

    
    
    import logging, copy
    from django.utils.log import DEFAULT_LOGGING
    
    LOGGING = copy.deepcopy(DEFAULT_LOGGING)
    LOGGING['filters']['suppress_deprecated'] = {
        '()': 'mysite.settings.SuppressDeprecated'  
    }
    LOGGING['handlers']['console']['filters'].append('suppress_deprecated')
    
    class SuppressDeprecated(logging.Filter):
        def filter(self, record):
            WARNINGS_TO_SUPPRESS = [
                'RemovedInDjango18Warning',
                'RemovedInDjango19Warning'
            ]
            # Return false to suppress message.
            return not any([warn in record.getMessage() for warn in WARNINGS_TO_SUPPRESS])
    

The 'mysite.settings.SuppressDeprecated' string needs to change if the root
website module (or filter location and/or name) is different.

