KRISHNANDU RANJN ROY
KRISHNANDU RANJN ROY

Reputation: 49

ModuleNotFoundError: No module named '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',
}

I'm trying to add Swagger UI in Django API, but I'm getting this error ModuleNotFoundError: No module named 'drf_spectacular.views'. enter image description here

Upvotes: 2

Views: 6667

Answers (2)

Ankit kumar
Ankit kumar

Reputation: 21

For me when I placed 'drf_spectacular' at end in INSTALLED_APPS it worked!

like INSTALLED_APPS = [ ... , 'drf_spectacular']

Upvotes: 1

Try moving 'drf_spectacular' to the end of the INSTALLED_APPS list.

The order in INSTALLED_APPS affects the order in which apps are initialized by Django. If drf_spectacular needs to inspect or integrate with other apps, those apps should be initialized before drf_spectacular.

Upvotes: 1

Related Questions