英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论