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

huangapple go评论88阅读模式
英文:

Django cannot import name 'Response' from 'rest_framework'

问题

我有一个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

得分: 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

huangapple
  • 本文由 发表于 2023年8月11日 00:53:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76877820.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定