[Fixed]-Change default Django REST Framework home page title

42👍

After finding this answer – found it finally in the docs.
In case anyone is searching – I recommend checking out this browsable api section in the docs.

From the docs:

To customize the default style, create a template called
rest_framework/api.html that extends from rest_framework/base.html.

A sample file could be (templates/rest_framework/api.html):

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

{% block branding %}
    <a class="navbar-brand" rel="nofollow" href="#">
        {% trans 'My new title' %}
    </a>
{% endblock %}

5👍

In your templates directory make a folder called rest_framework inside that make a file called api.html and paste the following line in it {% extends "rest_framework/base.html" %}. Now to change the branding add

{% block branding %}
Your Branding
{% endblock %}

and for changing the title you add a title block and etc.

4👍

From the code, it looks like it’s actually not a setting. You’ll need to override the ‘branding’ block in the base template with your own content.

Basically you will need to make a copy of Django REST Framework’s ‘base.html’ template file in your project’s template directory with the same relative path, which will cause it to be loaded instead of DRF’s template, and replace the content of that block template tag with your branding.

👤macro

Leave a comment