Django:追踪DeprecationWarning的原因 [英] Django: track down causes of DeprecationWarning

查看:212
本文介绍了Django:追踪DeprecationWarning的原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经升级到Django 1.4,现在当我运行我的开发服务器时,我得到以下警告:

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:基于功能的通用视图已被弃用;
改为使用基于类的视图。
DeprecationWarning

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

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

但是,我仍然收到警告,不能弄清楚我错过了什么如何获取导致DeprecationWarning的代码中的实际模块和行?

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?

推荐答案

您可以使用 warnings 模块引发的错误DeprecationWarning

临时将以下代码片段添加到项目的顶部 urls.py

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

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

DeprecationWarning 现在会引发错误,所以如果 debug = True 您将获得熟悉的黄色Django错误页面,并提供完整的追溯。

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.

如果您刚刚使用警告模块,则可能会发现本周Python模块的页面比Python文档更简单。

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.

这篇关于Django:追踪DeprecationWarning的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆