51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

Django 无法从 ‘rest_framework’ 导入 ‘Response’。

英文:

Django cannot import name 'Response' from 'rest_framework'

问题 {#heading}

我有一个Django rest_framework项目,一切正常运行。我正在使用pipenv,并使用它来安装django_rest_framework。我可以从rest_framework导入诸如serializer之类的函数并无问题地使用它们。

我想使用rest_framework的Response类,如这里所示,并在这里描述,所以我写了:

from rest_framework import Response

这在VSCode的语法检查中没有出错。

然而,当我启动服务器时,我收到以下消息:

无法从'rest_framework'导入名称'Response'

欢迎任何帮助。 英文:

I have a Django rest_framework project which is working fine. I am using pipenv and used it to install django_rest_framework. I can import functions such as serializer from rest_framework and use them without problems.

I would like to use rest_framework's Response class as givenhere and described here, so I wrote

from rest_framework import Response

This is not faulted by VSCode's syntax checks.

However, when I start the server I receive the message

 cannot import name 'Response' from 'rest_framework'

All help welcome

答案1 {#1}

得分: 7

You need to import from the response module like this:

文档中,你需要像这样从 response 模块导入:

from rest_framework.response import Response

英文:

From the docs you need to import from response module like this:

from rest_framework.response import Response

赞(1)
未经允许不得转载:工具盒子 » Django 无法从 ‘rest_framework’ 导入 ‘Response’。