How to disable “Django Login” page when trying to access swagger api in browser?

纵然是瞬间 提交于 2021-02-20 02:52:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!