如何修复Django 1.9中的弃用警告

sgp*_*rne 4 python django rest django-views django-rest-framework

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

RemovedInDjango110Warning:'get_all_related_objects是一个已弃用的非官方API.你可以用opts.get_all_related_objects()中的关系'get_fields()'替换它

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

我也得到了这个:

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

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

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

Wto*_*wer 6

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

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

这只在Django代码中记录:

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.
Run Code Online (Sandbox Code Playgroud)

它可以通过除去使用容易地固定RequestContextContextrender()和简单地传递一个字典.

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