Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't modify django rest framework base.html file

I'm using django rest framework, and as discribed here : django rest framework doc I've added /rest_framework/api.html in my templates dir.

The structure now is :

|
|\
| apps
|  \
|   settings.py
\
 templates
  \
   rest_framework
    \
     api.html

api.html :

{% extends "rest_framework/base.html" %}

{% block footer %}
    Hello !
{% endblock %}

settings.py :

...

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

...

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.admin',
    'django.contrib.admindocs',
    'django.contrib.markup',
    'django.contrib.webdesign',
     ...
    'rest_framework',
     ...


)

...

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework.authentication.SessionAuthentication',
    ),
    'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',),
    'PAGINATE_BY': 10
}

The modification I do in api.html are not displayed in the browsable api. What am I doing wrong ?

like image 236
Laurent Avatar asked Sep 23 '14 09:09

Laurent


1 Answers

There is an easier solution. Simply put 'rest_framework' at the bottom of your INSTALLED_APPS list. Or at least after the app where you are overriding the api template. This way, django will go to your app's templates folder searching for api.html template before going to rest_framework tempalte folder.

Let's call this app 'myapi'. In my case I have:

Project Structure

project/
    myapi/
        templates/
            api/
                ...
            rest_framework/
                app.html

settings.py

INSTALLED_APPS = (
    ...
    'myapi',
    'rest_framework'
)

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                ...
            ],
            'debug': DEBUG
        },
    },
]
like image 90
kiril Avatar answered Sep 18 '22 12:09

kiril