0
Django version 1.4.3

class FooTestCase(TestCase):

    def test_deprecation_warning(self):

        from django.template.loader import render_to_string
        tpl = render_to_string('template.html')

在运行时,这会生成一个DeprecationWarning

C:\Python26\lib\site-packages\django\views\generic\simple.py:8: DeprecationWarning: Function-based generic views have been deprecated; use class-based views instead.

为什么?迁移页面中没有提到它https://docs.djangoproject.com/en/1.3/topics/generic-views-migration/

4

1 回答 1

1

您可以通过 Python警告控制命令行选项获取此警告的回溯,-W以轻松查看使用已弃用的django.views.generic.simple.

python -W error:::django.views.generic.simple manage.py test

对于 Django 1.4 的简单 template.html,您的测试用例不会报告任何 DeprecationWarning。您可能使用了一个过时的模板标签来导入这个不推荐使用的模块。

Python 警告控制 和 DeprecationWarning 的更多信息 在我的回答中。

于 2013-05-09T12:01:15.480 回答