Django REST Framework + Django REST Swagger

2.2k Views Asked by At

Having a hard time configuring Swagger UI Here are the very explanatory docs in - https://django-rest-swagger.readthedocs.io/en/latest/. My settings.py looks like this.

enter image description here

urls.py looks like this.

enter image description here

But the swagger web page isn't loading properly.

enter image description here

and the console log is as follows.

enter image description here

What might be the problem here?

2

There are 2 best solutions below

0
On

very first, install django rest framework into your application and import that in setting.py file

make few APIs using DRF and then add swagger setting inside your setting.py file

SWAGGER_SETTINGS = {
   'SECURITY_DEFINITIONS': {
    'api_key': {
        'type': 'apiKey',
        'in': 'header',
        'name': 'Authorization'
    }
},  # setting to pass token in header
'USE_SESSION_AUTH': False,
# set to True if session based authentication needed
'JSON_EDITOR': True,
'api_path': 'api/',
'api_version': 'v0',

"is_authenticated": False,  # Set to True to enforce user authentication,
"is_superuser": False,  # Set to True to enforce admin only access
'unauthenticated_user': 'django.contrib.auth.models.AnonymousUser',
# unauthenticated user will be shown as Anonymous user in swagger UI.

}

Note:- You can edit the swagger setting according to you need.

1
On

Take a look at django-rest-swagger schema documentation, there is some code examples there about how this ties into DRF. You can read some more about this by visiting the DRF Schema Generator documentation.

If you just want to get up and running without learning more about the library, this article does a good job about showing project architecture and integrating DRS with DRF.