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.
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.
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.
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.
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.
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 %}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With