[英]Why newly created project doesn't display built-in API Django documentation?
我在这篇文章中描述了一个问题,我不知道问题的原因是什么,所以我决定像没有它一样在Docker中创建一个新项目。 在这两种情况下,我都会遇到相同的问题。 为了新创建的项目,我只添加到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))
]
在Docker requirements.txt
添加coreapi
。 在没有Docker的项目中,我通过virtualenv pip3 install coreapi
。 我认为这就是所有工作,以便从文档中获得本网站顶部的视图,显然是在http://localhost:8000/docs/
但是在两种情况下,我都可以
位于/ docs /的TemplateDoesNotExist
rest_framework /文档/ index.html中
Django尝试按以下顺序加载这些模板:
使用引擎django:
django.template.loaders.app_directories.Loader:/usr/local/lib/python3.6/site-packages/django/contrib/admin/templates/rest_framework/docs/index.html(源不存在)
django.template.loaders.app_directories.Loader:/usr/local/lib/python3.6/site-packages/django/contrib/auth/templates/rest_framework/docs/index.html(源不存在)
(在virtualenv中只有不同的路径)
有人知道什么地方可能出问题吗? 如果需要更多详细信息,请立即将其添加到这篇文章中。
更新当我将rest_framowork
添加到INSTALLED_APPS
我得到:
AttributeError at /docs/
'NoneType' object has no attribute 'items'
Request Method: GET
Request URL: http://localhost:8001/docs/
Django Version: 1.11
Exception Type: AttributeError
Exception Value:
'NoneType' object has no attribute 'items'
Exception Location: /usr/local/lib/python3.6/site-packages/rest_framework/templatetags/rest_framework.py in items, line 244
Python Executable: /usr/local/bin/python3
Python Version: 3.6.1
Python Path:
['/code',
'/usr/local/lib/python36.zip',
'/usr/local/lib/python3.6',
'/usr/local/lib/python3.6/lib-dynload',
'/usr/local/lib/python3.6/site-packages']
在模板/Users/myUser/Projects/DjangoTest/lib/python3.6/site-packages/rest_framework/templates/rest_framework/docs/sidebar.html中,第8行错误
UPDATE2我的应用程序位于INSTALLED_APPS
顶部的heroku rest_framowork
上,但是http://myapp.herokuapp.com/docs/
返回:
AttributeError at /docs/
'NoneType' object has no attribute 'items'
Request Method: GET
Request URL: http://myapp.herokuapp.com/docs/
Django Version: 1.11
Exception Type: AttributeError
Exception Value:
'NoneType' object has no attribute 'items'
Exception Location: /app/.heroku/python/lib/python3.6/site-packages/rest_framework/templatetags/rest_framework.py in items, line 244
Python Executable: /app/.heroku/python/bin/python
Python Version: 3.6.1
Python Path:
['/app/Project/backend/project',
'/app/.heroku/python/bin',
'/app',
'/app/.heroku/python/lib/python36.zip',
'/app/.heroku/python/lib/python3.6',
'/app/.heroku/python/lib/python3.6/lib-dynload',
'/app/.heroku/python/lib/python3.6/site-packages']
Server time: Mon, 17 Jul 2017 12:49:49 +0000
解决方案我在requirements.txt中使用djangorestframework==3.6.2
代替djangorestframework==3.6.3
。 我不知道为什么3.6.3版本不起作用。
这可能意味着您没有在settings.py
文件中将rest_framework
添加到INSTALLED_APPS
中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.