Reputation: 49
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'.
Upvotes: 2
Views: 6667
Reputation: 21
For me when I placed 'drf_spectacular'
at end in INSTALLED_APPS
it worked!
like INSTALLED_APPS = [ ... , 'drf_spectacular']
Upvotes: 1
Reputation: 11
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