简体   繁体   中英

uWSGI + Django: How can I get Django's deprecation warnings to be treated as errors?

My goal is to treat Django's deprecation warnings as errors. I've been experimenting with a copy of Django 1.9 and haven't been able to get it work like (I think) it should with uWSGI. This is what I've done:

In my settings.py file, I changed django. template .context_processors.debug django. template .context_processors.debug to django. core .context_processors.debug django. core .context_processors.debug in order to cause RemovedInDjango110Warning to be raised. I then ran runserver and accessed the site. The warning showed up in the runserver output but, as expected, it wasn't treated like an error.

Next, I ran export PYTHONWARNINGS=error . After that, I ran runserver and accessed the site. This time, the warning was treated like an error, which is what I want.

In an attempt to replicate this behavior with uWSGI, I added this to my uWSGI conf file:

env = PYTHONWARNINGS=error

I then accessed the site. The warning showed up in the uWSGI log, but it wasn't treated like an error. To confirm that the PYTHONWARNINGS environment variable was being set, I added this to my wsgi.py file:

print('PYTHONWARNINGS: %s' % os.environ.get('PYTHONWARNINGS', '[not set]'))

This caused PYTHONWARNINGS: error to be output in the uWSGI log, so I'm not sure what the problem is. Any ideas?

It's not uWSGI configuration solution, but you can add the following snippet to the top of your project's urls.py :

import warnings
warnings.simplefilter('error', DeprecationWarning)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM