django.template.exceptions.TemplateDoesNotExist: rest_framework/api.html

我们使用浏览器输入http://127.0.0.1:8000/就会抛出这个错误

raise TemplateDoesNotExist(template_name, chain=chain)
django.template.exceptions.TemplateDoesNotExist: rest_framework/api.html

TemplateDoesNotExist at /
rest_framework/api.html
Request Method:	GET
Request URL:	http://127.0.0.1:8000/
Django Version:	3.1.4
Exception Type:	TemplateDoesNotExist
Exception Value:	
rest_framework/api.html
Exception Location:	C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\django\template\loader.py, line 19, in get_template
Python Executable:	C:\Users\Administrator\AppData\Local\Programs\Python\Python37\python.exe
Python Version:	3.7.9
Python Path:	
['D:\\dgtest\\bookmanager',
 'D:\\dgtest\\bookmanager',
 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\python37.zip',
 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\DLLs',
 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\lib',
 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37',
 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages',
 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\win32',
 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\win32\\lib',
 'C:\\Users\\Administrator\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\Pythonwin']
Server time:	Thu, 23 Dec 2021 06:57:24 +0000

这是因为我们的python没在settings中的app中注册我们的rest_framework导致的。

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'books'
]

注册一下即可正常访问了。