Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Rest 'api-docs' is not a registered namespace

I'm setting the docs for my api and when I ask for (http://localhost:8000/api/v0/docs/) The app show me this error:

NoReverseMatch at /api/v0/docs/
'api-docs' is not a registered namespace

when try to do this

<script src="{% url **'api-docs:schema-js'** %}"></script>

this is my urls.py file:

from django.contrib import admin
from django.conf.urls import url, include
from django.contrib.auth.models import User
from . import views

from rest_framework import routers, serializers, viewsets

from rest_framework.documentation import include_docs_urls

# Routers provide an easy way of automatically determining the URL conf.
router = routers.DefaultRouter()
router.register(r'goals', views.GoalViewSet)


urlpatterns = [
    url(r'^goals/$', include(router.urls)),
    url(r'^docs/', include_docs_urls(title='My API title')),
]

I added the namespace to include_docs_urls but it doesn't work. (I have installed coreapi, pygments and markdown).

Beforehand thanks for helping me.

like image 629
Iván Casanova Avatar asked Aug 23 '17 01:08

Iván Casanova


1 Answers

You should move your docs url pattern into your main urls.py file. This is still a problem in DRF, there is also an issue opened on the official GitHub source: https://github.com/encode/django-rest-framework/issues/4984

The official developer of Django REST Framework, Tom Christie, says:

It's important enough that I'd like to see it highly prioritized, but there's a lot of other things going on at the moment too. Even after we release 3.6.3, there's still also all the work towards 3.7.0's realtime integration.

So your docs pattern should not have any prefixes (like api/v0/).

In conclusion, change your main urls.py:

url(r'^docs/', include_docs_urls(title='API Title'))
like image 85
wencakisa Avatar answered Nov 15 '22 00:11

wencakisa