Привет, я получаю эту ошибку, пожалуйста, помогите мне. я новичок в этом поле и получаю эту ошибку.
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'first',
]
my views.py
from django.shortcuts import render
from rest_framework.viewsets import ModelViewSet
from .serializers import MovieSerializer,RatingSerializers
from .models import Movie,Rating
# Create your views here.
class MovieViewSet(ModelViewSet):
queryset=Movie.objects.all()
serializer_class=(MovieSerializer,)
class RatingViewSet(ModelViewSet):
queryset=Rating.objects.all()
serializer_class=(RatingSerializers,)
мой основной urls.py
"""rest_project URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path,include
urlpatterns = [
path('admin/', admin.site.urls),
path('my_apis',include('first.urls')),
]
и serializers.py
from rest_framework import serializers
from .models import Movie,Rating
class MovieSerializer(serializers.ModelSerializer):
class Meta:
model= Movie
fields=['title','description']
class RatingSerializers(serializers.ModelSerializer):
class meta:
model=Rating
fields='__all__'
models.py - это
from django.db import models
from django.contrib.auth.models import User
from django.core.validators import MinValueValidator,MaxValueValidator
# Create your models here.
class Movie(models.Model):
title=models.CharField(max_length=20)
description =models.TextField(max_length=500)
def __str__(self):
return self.title
class Rating(models.Model):
movie=models.ForeignKey(Movie,on_delete=models.CASCADE)
user=models.ForeignKey(User,on_delete=models.CASCADE)
rating=models.PositiveIntegerField(validators=[MinValueValidator(1),MaxValueValidator(5)])
class Meta:
unique_together=(('user','movie'))
index_together=(('user','movie'))
my urls.py (приложение)
from django.urls import path
from django.conf.urls import include
from rest_framework import routers
from .views import ModelViewSet,RatingViewSet
router=routers.DefaultRouter()
router.register('movies',ModelViewSet,basename='Movie')
router.register('rating',RatingViewSet,basename='Rating')
app_name='first'
urlpatterns = [
path('',include('router.urls')),
]
Я следую видеоуроку
и получаю эту ошибку
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'router'
Пожалуйста, помогите мне игнорируйте, что этот текст следует избегать "похоже, что пост в основном код Пожалуйста, добавьте что-нибудь "