6👍
Please note that the DRF attempts to return data in the same format that was requested. From your browser, this is most likely HTML. To specify an alternative response, use the ?format=
parameter. For example: ?format=json
.
The TemplateDoesNotExist
error occurs most commonly when you are visiting an API endpoint in your browser and you do not have the rest_framework
included in your list of installed apps, as described by other respondents.
If you do not have DRF included in your list of apps, but don’t want to use the HTML Admin DRF page, try using an alternative format to ‘side-step’ this error message.
More info from the docs here: http://www.django-rest-framework.org/topics/browsable-api/#formats
- [Django]-How to rename items in values() in Django?
- [Django]-Django.db.utils.ProgrammingError: relation already exists
- [Django]-Django: Redirect to previous page after login
5👍
For me, rest_framework/api.html
was actually missing on the filesystem due to a corrupt installation or some other unknown reason. Reinstalling djangorestframework
fixed the problem:
$ pip install --upgrade djangorestframework
- [Django]-Django admin default filter
- [Django]-Django Rest Framework with ChoiceField
- [Django]-Django Footer and header on each page with {% extends }
4👍
Not your case, but also possible reason is customized loaders
for Django
. For example, if you have in settings (since Django 1.8
):
TEMPLATES = [
{
...
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages'
],
'loaders': [
'django.template.loaders.filesystem.Loader',
],
...
}
}]
Django will not try to look at applications folders with templates, because you should explicitly add django.template.loaders.app_directories.Loader
into loaders
for that.
Notice, that by default django.template.loaders.app_directories.Loader
included into loaders
.
- [Django]-Suppress "?next=blah" behavior in django's login_required decorator
- [Django]-Using Python's os.path, how do I go up one directory?
- [Django]-Cancel an already executing task with Celery?
0👍
I ran into the same error message. In my case, it was due to setting the backend to Jinja2. In my settings file:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.jinja2.Jinja2',
...
Changing this back to the default fixed the problem:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
...
Still not sure if there is a way to use the Jinja2 backend with rest_framework.
- [Django]-Django: Record with max element
- [Django]-Django database query: How to get object by id?
- [Django]-Django rest framework lookup_field through OneToOneField
0👍
We can get the error even if we missed adding the ‘rest_framework’ in the installed apps.
So please check that too if you are facing the error.
- [Django]-Missing Table When Running Django Unittest with Sqlite3
- [Django]-Make the first letter uppercase inside a django template
- [Django]-Django apps aren't loaded yet when using asgi