TemplateDoesNotExist: djangorestframework/api.html

5,941 views
Skip to first unread message

Libor Nenadál

unread,
Oct 5, 2012, 5:59:42 PM10/5/12
to django-res...@googlegroups.com
Hi,
I am very new to Django and REST framework so I am probably asking very stupid question, but how can I make html browsing work? I spent an hour googling and still nothing. :-(

When I try to access endpoint via html, I end up with exception from the subject. When I copied api.html from the djangorestframework sources into my application directory, it failed with missing base.html. And copying all the template files into the app directory does not seem like good idea to me.

Can anybody point me? Thanks a lot,

Libor



Vitor M. A. da Cruz

unread,
Oct 5, 2012, 9:23:00 PM10/5/12
to django-res...@googlegroups.com
   Hello Libor;

   You need to add 'django.contrib.staticfiles' to settings.INSTALLED_APPS. After that the templates will be found correctly.


--

   Vitor M. A. da Cruz

Max Arnold

unread,
Oct 5, 2012, 9:41:54 PM10/5/12
to django-res...@googlegroups.com
On Fri, Oct 05, 2012 at 10:23:00PM -0300, Vitor M. A. da Cruz wrote:
> Hello Libor;
>
> You need to add 'django.contrib.staticfiles' to settings.INSTALLED_APPS.
> After that the templates will be found correctly.

I think this is misleading, because templates are not static files and they need to be preprocessed before output.

Instead, you need to tell Django how to find required templates: https://docs.djangoproject.com/en/1.4/ref/templates/api/#loader-types
The easiest way is to just add 'djangorestframework' to settings.INSTALLED_APPS.

Ulises Reyes

unread,
Jul 3, 2013, 3:57:45 PM7/3/13
to django-res...@googlegroups.com

I ran into the same issue and added rest_framework to INSTALLED_APPS

Kike Coslado

unread,
Mar 9, 2014, 12:54:35 PM3/9/14
to django-res...@googlegroups.com
I'm in the same issue. Template loader don't find this template and i've setted installed apps with rest_framework and staticfiles, so i don't know what to do. Any help? Thnx

Carlton Gibson

unread,
Mar 10, 2014, 6:18:43 AM3/10/14
to django-res...@googlegroups.com
DRF's templates reside in `rest_framework/templates` — this is the standard per-app location. 

In order to be found two things need to be the case. 

1. `rest_framework` must be in your INSTALLED_APPS settings.
2. django.template.loaders.app_directories.Loader must be in your TEMPLATE_LOADERS

They'll look something like this:

    INSTALLED_APPS = (
        ...
        
        'rest_framework',

        ...
    )

    TEMPLATE_LOADERS = (
        'django.template.loaders.filesystem.Loader',
        'django.template.loaders.app_directories.Loader',
    )

It's worth reviewing the template loading documentation that Max linked to, but that's all there is to it. If a template is not found you'll get a list of locations that were searched trying to locate it. Check there that the directories you're expecting appear. 

Kind Regards,

Carlton
Reply all
Reply to author
Forward
0 new messages