如何在Django 1.9中修复废弃警告 [英] How to fix a Deprecation Warning in Django 1.9

查看:198
本文介绍了如何在Django 1.9中修复废弃警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Django框架的新用户。我目前正在使用django_rest_framework构建一个REST API。当我启动我的服务器时,我得到了不赞成的警告,我不知道如何解决。


RemovedInDjango110警告:'get_all_related_objects是一个非官方的API已被弃用您可以使用'get_fields()'
替换为opts.get_all_related_objects()中的关系


以上是其中的第一个。有谁知道如何解决这个问题。所有我在我的API中的一切都是使用内置的ModelViewSet进行的标准休息调用,并且我也覆盖了默认的认证&用户系统与我自己,所以我不知道为什么我得到这些警告,因为我一直在使用Django 1.9从一开始。



我也得到这个:


RemovedInDjango110警告:render()必须被调用一个dict,而不是一个RequestContext


从我的初步研究中,这与模板有关。我没有使用任何模板,所以我不知道为什么会这样。



任何人都可以帮我解决这些问题?

解决方案

您不需要修复弃用警告,因为只有警告和事情仍然有效。但是,如果您决定更新,可能会破坏您的应用程序。所以通常重要的是将这些部分重新写入新的接口警告,如果它们在你的代码中,那么这些警告会被暗示。如果您使用的是一些图书馆,那么您可能需要等待图书馆创作者在下一个版本中更新他/她的图书馆。



关于您的特定警告,除非你决定更新Django 1.10,你的代码应该很好。


I am a new user of the Django Framework. I am currently building a REST API with the django_rest_framework. When starting my server I am getting deprecation warnings that I have no idea how to fix.

RemovedInDjango110Warning: 'get_all_related_objects is an unofficial API that has been deprecated. You may be able to replace it with 'get_fields()' for relation in opts.get_all_related_objects()

The above is the first of these. Does anyone know how to fix this issue. All I have in my API at the minute is standard rest calls using the built in ModelViewSet and I have also overwritten the default authentication & user system with my own so I have no idea why I'm getting these warnings as I have been using Django 1.9 from the start.

I also got this:

RemovedInDjango110Warning: render() must be called with a dict, not a RequestContext

From my initial research this is related to templates. I am not using any templates so I don't know why this is coming up.

Can anyone help me to fix these issues?

解决方案

You don't have to "fix" Deprecation Warnings as they are, well, only warnings and things still work. However, if you'll decide to update they might break your app. So usually it's a good idea to rewrite the parts with warnings to new interfaces, that are hinted in those warnings if it's in your code. If it's in some side library you use, then you might want to wait if the library creator will update his/her library in the next release.

Regarding your particular warnings, unless you'll decide to update to Django 1.10, your code should work well.

这篇关于如何在Django 1.9中修复废弃警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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