2017-08-23 34 views
3

我設置文檔爲我的API,當我問(http://localhost:8000/api/v0/docs/)該應用程序顯示此錯誤:Django的休息「API的文檔」是不是已註冊的命名空間

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

時嘗試做這

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

這是我的urls.py文件:

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')), 
] 

我添加了命名空間include_docs_urls,但它不工作。 (我已經安裝了coreapi,pygments和markdown)。

事前感謝我的幫助。

+3

嘗試在你的** **主'urls.py'文件移動文檔的URL。 – wencakisa

+0

https://groups.google.com/forum/#!topic/django-rest-framework/d0L3jVMqp2Y,https://github.com/encode/django-rest-framework/issues/4984好像DRF 3.6.2如果您將API版本添加到您的網址(如'/ api/v0'),docs會中斷。 –

+0

@wencakisa是的,我感動的文檔/ URL到urls.py主文件,它的工作。謝謝!。 –

回答

2

您應該將您的docs網址格式轉換爲您的主文件urls.py文件。這仍然是DRF一個問題,還有一個問題,官方的GitHub源開:https://github.com/encode/django-rest-framework/issues/4984

Django的REST框架,Tom Christie,官方開發人員表示:

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.

所以你docs模式不應該有任何前綴(如api/v0/)。

總之,改變你的主要urls.py

url(r'^docs/', include_docs_urls(title='API Title')) 
相關問題