Reputation: 7615
I've installed Django-Rest-Swagger and done what I can to set it up. From looking at the docs, I don't really understand if I need to do any more to make it work.
If I go to localhost:800/docs
I see this:
If I navigate to that URL, I see this JSON:
So if those exist, what would stop it from finding them?
I don't think it's that I have a model serializer I don't see why that would be. I also found this, but I don't think that's it either.
Swagger settings:
SWAGGER_SETTINGS = {
'exclude_namespaces': [],
'api_version': '0.1',
'api_path': '/characters/api',
'enabled_methods': [
'get',
'post',
'put',
'patch',
'delete'
],
'api_key': '',
'is_authenticated': False,
'is_superuser': False,
'permission_denied_handler': None,
'info': {
'contact': '[email protected]',
'description': 'This is a nWoD-DB Api thing',
'license': 'No Licence',
'licenseUrl': '',
'termsOfServiceUrl': '',
'title': 'nWoD-DB',
},
'doc_expansion': 'none',
}
Urls.py
#urls.py
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'nwod_characters.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^characters/', include('characters.urls')),
url(r'^djangular/', include('djangular.urls')),
url(r'^api-auth/', include('rest_framework.urls',
namespace='rest_framework')),
url(r'^docs/',
include('rest_framework_swagger.urls')),
)
#characters/urls.py
mage_list = MageViewSet.as_view({
'get': 'list',
'post': 'create'
})
mage_detail = MageViewSet.as_view({
'get': 'retrieve',
'put': 'update',
'patch': 'partial_update',
'delete': 'destroy'
})
user_list = UserViewSet.as_view({
'get': 'list'
})
user_detail = UserViewSet.as_view({
'get': 'retrieve'
})
urlpatterns = format_suffix_patterns([
url(r'^api/root$', api_root),
url(r'^api/mages$', mage_list, name='mage-list'),
url(r'^api/mages/(?P<pk>[0-9]+)$', mage_detail, name='mage-detail'),
url(r'^api/users$', user_list, name='user-list'),
url(r'^api/users/(?P<pk>[0-9]+)$', user_detail, name='user-detail'),
])
urlpatterns += [url(r'^$', IndexView.as_view(), name='index'), ]
Upvotes: 3
Views: 3165
Reputation: 29
The 'problem' is that you are doing "include('characters.urls')" as far as I can find, rest_framework_swagger has a hard time finding any urls that aren't explicitly in your root urlpatterns - if you want to guarantee that swagger will find them you'll have to expand them into your urlpatterns instead of including them from another file, i.e.:
urlpatterns = patterns('',
# Examples:
# url(r'^$', 'nwod_characters.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),
url(r'^admin/', include(admin.site.urls)),
url(r'^api/root$', api_root),
url(r'^api/mages$', mage_list, name='mage-list'),
url(r'^api/mages/(?P<pk>[0-9]+)$', mage_detail, name='mage-detail'),
url(r'^api/users$', user_list, name='user-list'),
url(r'^api/users/(?P<pk>[0-9]+)$', user_detail, name='user-detail'),
....
I'd be happy to know if anyone has a way to configure swagger to avoid having to lump all of the urls.
Upvotes: 2