问题
I am getting a blank page with just a "Django Login" link when trying to access generated swagger docs. I am using drf_yasg library to render swagger documentation.
Code to generate swagger docs is similar to mentioned in swagger docs.
schema_view = get_schema_view(
openapi.Info(
title="Snippets API",
default_version='v1',
description="Test description",
terms_of_service="https://www.google.com/policies/terms/",
contact=openapi.Contact(email="contact@snippets.local"),
license=openapi.License(name="BSD License"),
),
public=True,
permission_classes=(permissions.AllowAny,),
)
回答1:
You will need to add the following to your settings.py
per the docs
SWAGGER_SETTINGS = {
'USE_SESSION_AUTH': False
}
回答2:
Thanks Akshay for your answer. I tried changing it to false and tried accessing the swagger UI from incognito, but still I see the blank page.
I see my user and Logout link.
Django sriram Django Logout
回答3:
I recently came across the same issue, it seems that in my case I had changed the location of the static files to be uploaded to an s3 bucket where it couldn't find the scripts and styles and therefor showed a blank screen, to test things out I returned the default settings for the static files in django, you can also make sure of that by inspecting the blank page and making sure that you're not getting 404 errors , maybe your case was similar ?
来源:https://stackoverflow.com/questions/62031565/how-to-disable-django-login-page-when-trying-to-access-swagger-api-in-browser