如何修复Django 1.9

时间:2016-01-25 20:48:22

标签: python django rest django-views django-rest-framework

我是Django Framework的新用户。我目前正在使用django_rest_framework构建REST API。启动我的服务器时,我收到了弃用警告,我不知道如何修复。

  

RemovedInDjango110Warning:' get_all_related_objects是一个已弃用的非官方API。您可以将其替换为' get_fields()'     for opts.get_all_related_objects()

中的关系

以上是第一个。有谁知道如何解决这个问题。我现在在API中的所有内容都是使用内置ModelViewSet的标准休息调用,并且我还覆盖了默认身份验证&我自己的用户系统所以我不知道为什么我从一开始就使用Django 1.9时会收到这些警告。

我也得到了这个:

  

RemovedInDjango110Warning:必须使用dict调用render(),而不是使用RequestContext

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

有人可以帮我解决这些问题吗?

2 个答案:

答案 0 :(得分:6)

如果有人在这里登陆,请特别注意第二次弃用警告:

  

RemovedInDjango110Warning:必须使用dict调用render(),而不是使用RequestContext

这只记录在Django code

def render(self, context=None, request=None):
    # A deprecation path is required here to cover the following usage:
    # >>> from django.template import Context
    # >>> from django.template.loader import get_template
    # >>> template = get_template('hello.html')
    # >>> template.render(Context({'name': 'world'}))
    # In Django 1.7 get_template() returned a django.template.Template.
    # In Django 1.8 it returns a django.template.backends.django.Template.
    # In Django 1.10 the isinstance checks should be removed. If passing a
    # Context or a RequestContext works by accident, it won't be an issue
    # per se, but it won't be officially supported either.

可以通过从RequestContext移除Contextrender()并简单地传递字典来轻松修复。

在v1.9中保留它并不是最好的事情。正如Django开发人员所说,它可能会或可能不会很好。不同的是,在1.9中我们得到了弃用警告。

答案 1 :(得分:3)

您不必“修复”弃用警告,因为它们只是警告和事情仍然有效。但是,如果您决定更新,则可能会破坏您的应用。因此,通常最好用新警告对新接口重写部件,如果它存在于您的代码中,则会在这些警告中暗示。如果它在您使用的某个侧库中,那么您可能想要等待库创建者在下一个版本中更新他/她的库。

关于您的特定警告,除非您决定更新到Django 1.10,否则您的代码应运行良好。