ModuleNotFoundError: Нет модуля с именем 'drf_spectacular.views'

urls.py

from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, 
SpectacularSwaggerView
from django.contrib import admin
from django.urls import path, include


urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/schema/', SpectacularAPIView.as_view(), name='api-schema'),
    path('api/docs/', SpectacularSwaggerView.as_view(url_name='api-schema'), name='api-docs'),
    path('api/redoc/', SpectacularRedocView.as_view(url_name='api-schema'), name='api-redoc'),
    path('api/user/', include('user.urls')),
    path('api/recipe/', include('recipe.urls')),
]

settings.py

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'drf_spectacular',
'core',
'user',
'recipe',
]

requirements.txt

drf-spectacular
# drf-spectacular>=0.15,<0.16

REST_FRAMEWORK = {
    'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
}

Я пытаюсь добавить Swagger UI в Django API, но получаю эту ошибку ModuleNotFoundError: Нет модуля с именем 'drf_spectacular.views'. enter image description here

У меня была такая же проблема на Windows VSCode, я решил ее установкой вне venv. Я не проверял, почему, но, похоже, это связано с версией зависимостей или просто со старым добрым Path.

Вернуться на верх