Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change default Django REST Framework home page title

I am following the article to set up a new Djangon REST framework project. I got it working but I would like to change the default home page title from Django REST Framework v3.3.2 to my own, I am sure it's just a setting somewhere but it didn't seem obvious which one, any insights will be appreciated. Thanks.

UPDATE Based on the hints from @macro and this article, I got it to work with api.html. Thanks.

like image 955
Bob Avatar asked Aug 06 '16 00:08

Bob


People also ask

What is browsable API Django?

The browsable API feature in the Django REST framework generates HTML output for different resources. It facilitates interaction with RESTful web service through any web browser. To enable this feature, we should specify text/html for the Content-Type key in the request header.

What is default router in Django REST framework?

DefaultRouter. This router is similar to SimpleRouter as above, but additionally includes a default API root view, that returns a response containing hyperlinks to all the list views. It also generates routes for optional . json style format suffixes.

What is JSONRenderer in Django?

Second thing is, you have to return serializer. data back to client in form of JSON, not dictionary. Thats what JSONRenderer does. It convert dict to JSON and its implemented inside Response class https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/response.py.

What is Paginate_queryset?

The paginate_queryset method is passed to the initial queryset and should return an iterable object. That object contains only the data in the requested page. The get_paginated_response method is passed to the serialized page data and should return a Response instance.


2 Answers

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 %}
like image 109
Gilad E. Avatar answered Oct 03 '22 05:10

Gilad E.


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.

like image 30
macro Avatar answered Oct 03 '22 04:10

macro