[英]ModuleNotFoundError: No module named 'music_controller.api'
When I run the server, I am getting the following error:当我运行服务器时,我收到以下错误:
from music_controller.api.models import Room
ModuleNotFoundError: No module named 'music_controller.api'
I think the problem is from the import in the views.py
:我认为问题出在
views.py
的导入:
from django.shortcuts import render
from rest_framework import generics
from .serializers import RoomSerializer
from .models import Room
# Create your views here.
class RoomView(generics.CreateAPIView):
queryset = Room.objects.all()
serializer_class = RoomSerializer
I made sure that the app name is included in INSTALLED_APPS
in the settings.py
.我确保应用程序名称包含在
settings.py
INSTALLED_APPS
中。
The following is the tree of my project:以下是我的项目树:
In the music_controller directory, add a file called __init__.py
.在 music_controller 目录中,添加一个名为
__init__.py
的文件。 Leave the file empty.将文件留空。
Just got the same error, how did you fix it?刚刚遇到同样的错误,你是怎么解决的?
Edit : Just found that my problem is that this line from music_controller.api.models import Room
is somehow added at the first line of the views.py
, just remove it.编辑:刚刚发现我的问题是
from music_controller.api.models import Room
这一行以某种方式添加到views.py
的第一行,只需将其删除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.