ImportError:在创建demo rest api时无法导入名称UserSerializer

时间:2016-11-22 11:50:17

标签: python django api django-rest-framework

我正在尝试根据this教程在Django Rest Framework上构建一个休息服务。

我在尝试运行

时遵循了所有步骤
python manage.py createsuperuser

引发以下错误:

File "/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/tutorial/tutorial/urls.py", line 24, in <module>
from tutorial.quickstart import views
File "/tutorial/tutorial/quickstart/views.py", line 6, in <module>
from tutorial.quickstart.serializers import UserSerializer,    GroupSerializer
ImportError: cannot import name UserSerializer

2 个答案:

答案 0 :(得分:2)

确保信息实际上在serializers.py中,并且教程是项目名称,并且 quickstart 您的应用名称

那你就可以写

from .serializers import UserSerializer, GroupSerializer

答案 1 :(得分:-1)

您需要从中删除“ tutorial”一词。使用:

from quickstart.serializers import UserSerializer, GroupSerializer