简体   繁体   中英

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. In both cases I get the same problem. To wit to newly created project I add only to 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 . In case of project without Docker I install via 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

TemplateDoesNotExist at /docs/

rest_framework/docs/index.html

Django tried loading these templates, in this order:

Using engine 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/auth/templates/rest_framework/docs/index.html (Source does not exist)

(in virtualenv there is only different path)

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:

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

UPDATE2 I have in my app on heroku rest_framowork at the top of INSTALLED_APPS however http://myapp.herokuapp.com/docs/ returns:

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. I have no idea why version 3.6.3 doesn't work.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM