django ModuleNotFoundError:没有名为“drf_spectacular.views”的模块

dced5bon  于 2023-05-19  发布在  Go
关注(0)|答案(1)|浏览(326)

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',
}

我试图在Django API中添加Swagger UI,但我得到了这个错误ModuleNotFoundError:没有名为'drf_spectacular. views'的模块。

kr98yfug

kr98yfug1#

我在Windows VSCode上遇到了同样的问题,通过在venv外部安装解决了这个问题。我还没有检查为什么,但它似乎涉及到依赖版本或只是好的'ol路径。

相关问题