Search code examples
djangoswaggerdrf-yasg

drf-yasg Django restframework Swagger Page return blank page with django login a href link


Hi I try to add to my project swagger but it return 401 error , please help me about it

it is my router

from . import router
    schema_view = get_schema_view(
        openapi.Info(
            title='EduOn API',
            description="EduOn API",
            default_version='v1',
            terms_of_service='https://www.google.com/policies/terms/',
            contact=openapi.Contact(email="algoritmgateway@gmail.com"),
            license=openapi.License(name='EduOn License'),
        ),
        public=True,
        permission_classes=(permissions.AllowAny,)
    )

register my routers:

urlpatterns += router.router.urls

in urlpatterns inside list :

#documents
    url(r'^swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
    url(r'^swagger/$', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
    url(r'^redoc/$', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),

and register in INSTALLED_APPS

I get my expecct output in onluy localhist:8000 but if i restart nginx and enter production website it get this output ( enter image description here


Solution

  • I faced the same issue. If you collected static files before you will need to collect static files again for swagger ui.

    python manage.py collectstatic