2013-03-25 61 views
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的Django 1.4:在運行時django.template.loader.render_to_string

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

DeprecationWarning爲什麼呢?它不是在遷移頁https://docs.djangoproject.com/en/1.3/topics/generic-views-migration/

+0

你確定它是'render_to_string'那是給你的警告嗎?你能告訴我們回溯嗎? – 2013-03-25 21:06:48

+0

如何生成棄用警告的回溯? – apelliciari 2013-03-25 21:09:41

+0

設置'warnings.filterwarnings('error')',然後你得到一個異常而不是一個警告([見文檔](http://docs.python.org/2.6/library/warnings.html#the-warnings -過濾))。 – 2013-03-25 21:14:44

回答

1

你可以得到此警告回溯由一個Python 警報控制命令行選項-W提到,看看有什麼方便使用過時的django.views.generic.simple

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

您的測試案例不會爲使用Django 1.4的簡單template.html報告任何DeprecationWarning報告。您可能使用導入此棄用模塊的廢棄模板標籤。

有關更多信息 Python warning control 和DeprecationWarning在我的answer中。