我正在尝试将文档添加到我的Django应用程序中。我按照official Django Built-in API documentation做了一切。但是,当我打开localhost:8000/docs/
时,我没有得到任何结果。只有白色屏幕。我希望得到像this这样的东西。我不知道出了什么问题。一切似乎都做得很好。我将coreapi
,markdown
和pygments
添加到requirements.txt
文件。
我的urls.py
:
from rest_framework.documentation import include_docs_urls
API_TITLE = 'API title'
API_DESCRIPTION = '...'
urlpatterns = [
url(r'^docs/', include_docs_urls(title=API_TITLE, description=API_DESCRIPTION))
]
日志:
django_1 | [16/Jul/2017 14:39:39] "GET /docs/ HTTP/1.1" 200 10156
django_1 | [16/Jul/2017 14:39:39] "GET /static/rest_framework/docs/css/bootstrap-theme.min.017404ba6919.css HTTP/1.1" 304 0
django_1 | [16/Jul/2017 14:39:39] "GET /static/rest_framework/docs/css/bootstrap.min.1825bc9de3d6.css HTTP/1.1" 304 0
django_1 | [16/Jul/2017 14:39:39] "GET /static/rest_framework/docs/css/font-awesome-4.0.3.3c6725a71cd2.css HTTP/1.1" 304 0
django_1 | [16/Jul/2017 14:39:39] "GET /static/rest_framework/js/coreapi-0.1.0.b8a6a6e33df8.js HTTP/1.1" 304 0
django_1 | [16/Jul/2017 14:39:39] "GET /static/rest_framework/docs/css/base.4fca6813aaab.css HTTP/1.1" 304 0
django_1 | [16/Jul/2017 14:39:39] "GET /static/rest_framework/docs/css/jquery.json-view.min.a2e6beeb6710.css HTTP/1.1" 304 0
django_1 | [16/Jul/2017 14:39:39] "GET /static/rest_framework/docs/js/jquery.json-view.min.b7c2d6981377.js HTTP/1.1" 304 0
django_1 | [16/Jul/2017 14:39:39] "GET /static/rest_framework/docs/js/jquery-1.10.2.min.628072e7212d.js HTTP/1.1" 304 0
django_1 | [16/Jul/2017 14:39:39] "GET /static/rest_framework/docs/js/api.d5c3cd5658db.js HTTP/1.1" 304 0
django_1 | [16/Jul/2017 14:39:39] "GET /static/rest_framework/docs/js/bootstrap.min.79b5346433d3.js HTTP/1.1" 304 0
django_1 | [16/Jul/2017 14:39:40] "GET /docs/schema.js HTTP/1.1" 200 7456
MacBook-Pro:DockerProject myUser $ coreapi get get http://localhost:8000/docs/:
<Error: 403 Forbidden>
detail: "Authentication credentials were not provided."
SOLTUION
我在requirements.txt中使用了djangorestframework==3.6.2
而不是djangorestframework==3.6.3
。我不知道版本3.6.3为什么不起作用。
答案 0 :(得分:0)
我遇到了和你一样的问题。 我将问题更正如下。
在您的代码中:
urlpatterns = [
url(r'^docs/', include_docs_urls(title=API_TITLE, description=API_DESCRIPTION))
]
更改为:
urlpatterns = [
url(r'^docs/', include_docs_urls(title=API_TITLE, public=True, permission_classes=[]))
]