Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
448 views
in Technique[技术] by (71.8m points)

warnings - Django: track down causes of DeprecationWarning

I've upgraded to Django 1.4 and now when I run my development server I get the following warning:

/home/flc/venvs/myprj/lib/python2.6/site-packages/django/views/generic/simple.py:8:

DeprecationWarning: Function-based generic views have been deprecated; use class-based views instead. DeprecationWarning

I have tracked down most of the causes of this and fixed them by making the following changes:

django.views.generic.simple.direct_to_template => django.views.generic.base.TemplateView django.views.generic.simple.redirect_to => django.views.generic.base.RedirectView

etc

However, I'm still getting the warning and can't figure out what I've missed. How do I get the actual module and line in my code that is causing the DeprecationWarning?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use the warnings module to raise an error for DeprecationWarning.

Temporarily add the following snippet to the top of your project's urls.py:

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

The DeprecationWarning will now raise an error, so if debug=True you'll get the familiar yellow Django error page with the full traceback.

Once you've tracked down the source of the deprecation warnings, remember to remove the snippet! Note that it may be a third party app that is causing the deprecation warnings, not your own code.

If you're new to the warnings module, you might find the page on Python module of the week to be an easier introduction than the Python docs.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...