简体   繁体   English

为什么新创建的项目不显示内置API Django文档?

[英]Why newly created project doesn't display built-in API Django documentation?

I have a problem described in this post I have no idea what is the reason of the problem so I decided to create a new project both in Docker like without it. 我在这篇文章中描述了一个问题,我不知道问题的原因是什么,所以我决定像没有它一样在Docker中创建一个新项目。 In both cases I get the same problem. 在这两种情况下,我都会遇到相同的问题。 To wit to newly created project I add only to urls.py : 为了新创建的项目,我只添加到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))
]

and in Docker requirements.txt I add coreapi . 在Docker requirements.txt添加coreapi In case of project without Docker I install via virtualenv pip3 install coreapi . 在没有Docker的项目中,我通过virtualenv pip3 install coreapi That is all what in my opinion I should do in order to get a view like at the top of this site from documentation Obviously at http://localhost:8000/docs/ However in both cases I get 我认为这就是所有工作,以便从文档中获得本网站顶部的视图,显然是在http://localhost:8000/docs/但是在两种情况下,我都可以

TemplateDoesNotExist at /docs/ 位于/ docs /的TemplateDoesNotExist

rest_framework/docs/index.html rest_framework /文档/ index.html中

Django tried loading these templates, in this order: Django尝试按以下顺序加载这些模板:

Using engine django: 使用引擎django:

django.template.loaders.app_directories.Loader: /usr/local/lib/python3.6/site-packages/django/contrib/admin/templates/rest_framework/docs/index.html (Source does not exist) 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 (Source does not exist) django.template.loaders.app_directories.Loader:/usr/local/lib/python3.6/site-packages/django/contrib/auth/templates/rest_framework/docs/index.html(源不存在)

(in virtualenv there is only different path) (在virtualenv中只有不同的路径)

Does anyone have an idea what might be wrong? 有人知道什么地方可能出问题吗? If more details will be needed I will add it immediately to this post, just let me know. 如果需要更多详细信息,请立即将其添加到这篇文章中。

UPDATE When I add rest_framowork to INSTALLED_APPS I get: 更新当我将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']

In template /Users/myUser/Projects/DjangoTest/lib/python3.6/site-packages/rest_framework/templates/rest_framework/docs/sidebar.html, error at line 8 在模板/Users/myUser/Projects/DjangoTest/lib/python3.6/site-packages/rest_framework/templates/rest_framework/docs/sidebar.html中,第8行错误

UPDATE2 I have in my app on heroku rest_framowork at the top of INSTALLED_APPS however http://myapp.herokuapp.com/docs/ returns: 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

SOLTUION I used djangorestframework==3.6.2 instead of djangorestframework==3.6.3 in requirements.txt. 解决方案我在requirements.txt中使用djangorestframework==3.6.2代替djangorestframework==3.6.3 I have no idea why version 3.6.3 doesn't work. 我不知道为什么3.6.3版本不起作用。

这可能意味着您没有在settings.py文件中将rest_framework添加到INSTALLED_APPS中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 内置的API Django文档没有显示任何内容 - The built-in API Django documentation doesn't display anything 内置的python帮助功能为什么不显示所有可能的命令? - Why doesn't the built-in python help function display all the possible commands? 为什么Pylint不喜欢内置函数? - Why doesn't Pylint like built-in functions? 为什么weakref 不支持Python 中的内置类型? - Why weakref doesn't support built-in types in Python? 如何从 Django 内置 API 文档中排除 rest-auth 端点? - How can I exclude rest-auth endpoint from the Django built-in API documentation? 为什么这个django-rest-swagger API文档不能正常显示/工作? - Why won't this django-rest-swagger API documentation display/work properly? classmethod内置函数-无法理解文档中的声明 - classmethod built-in function - Can't understand a statement from Documentation 离开内置的runserver后,为什么Django找不到我的管理媒体文件? - Why can't Django find my admin media files once I leave the built-in runserver? django好的风格:将内置目录复制到本地项目? - django good style: copy built-in directory to local project? 为什么我新安装的Django项目仅显示欢迎页面? - Why does my newly installed Django project only display the welcome page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM