I am trying to integrate swagger 2.0 with existing DRF application but it gives following error in browser after runningpython manage.py runserver
:
TemplateDoesNotExist at /swagger rest_framework_swagger/index.html Request Method: GET Request URL: http://127.0.0.1:8000/swagger Django Version: 1.10 Exception Type: TemplateDoesNotExist Exception Value: rest_framework_swagger/index.html Exception Location: C:\Users\MHAZIQ~1\Desktop\Tkxel\mmg-git\venv\lib\site-packages\django\template\loader.py in get_template, line 25
I have added following lines in views.py:
from rest_framework_swagger.views import get_swagger_view
schema_view = get_swagger_view(title='Pastebin API')
And I have added following lines in urls.py:
url(r'^swagger', views.schema_view),
I ve tried applying following solution: TemplateDoesNotExist at /docs/ rest_framework_swagger/index.html
but it didnot solve my problem, Can anyone please help me in this regard?
Add 'rest_framework_swagger' to INSTALLED_APPS in Django settings.
settings.py
INSTALLED_APPS = [
...
'rest_framework_swagger',
]
https://django-rest-swagger.readthedocs.io/en/latest/
After several hours of research I have found the problem with my code, as I was adding swagger into an existing project, it didnt have following parameters in settings.py:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},]
Now swagger works absolutely fine!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With