Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Django
  • Views
  • Model
  • Template
  • Forms
  • Jinja
  • Python SQLite
  • Flask
  • Json
  • Postman
  • Interview Ques
  • MongoDB
  • Python MongoDB
  • Python Database
  • ReactJS
  • Vue.js
Open In App
Next Article:
Browsable API in Django REST Framework
Next article icon

Disable Admin-Style Browsable Interface of Django REST Framework

Last Updated : 16 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Django REST Framework (DRF) is a powerful and flexible toolkit for building Web APIs in Django. One of its features is the browsable API, which provides a user-friendly, web-based interface for interacting with the API. While this can be helpful during development and debugging, it may not be desirable in a production environment for security or performance reasons. In this article, we will walk through the steps to disable the admin-style browsable interface of the Django REST Framework.

How to Disable Admin-Style Browsable Interface of Django REST Framework?

Step 1: Set Up a Django Project

First, we need to create a Django project and a Django app. You can skip this part if you already have a project set up. Otherwise, follow these steps:

Install Django and Django REST Framework:

pip install django djangorestframework

Create a Django Project:

django-admin startproject myproject
cd myproject

Create a Django App:

python manage.py startapp myapp

Add the App to Installed Apps:

Open myproject/settings.py and add 'myapp' and 'rest_framework' to the INSTALLED_APPS list:

INSTALLED_APPS = [
...
'rest_framework',
'myapp',
]
iop


Create a Simple Model:

Open myapp/models.py and create a simple model:

Python
from django.db import models  class Item(models.Model):     name = models.CharField(max_length=100)     description = models.TextField()      def __str__(self):         return self.name 

Create and Apply Migrations:

python manage.py makemigrations
python manage.py migrate

Create a Superuser:

python manage.py createsuperuser

Create a Serializer:

Open myapp/serializers.py and create a serializer for the Item model:

Python
from rest_framework import serializers from .models import Item  class ItemSerializer(serializers.ModelSerializer):     class Meta:         model = Item         fields = '__all__' 

Create a ViewSet:

Open myapp/views.py and create a viewset for the Item model:

Python
from rest_framework import viewsets from .models import Item from .serializers import ItemSerializer  class ItemViewSet(viewsets.ModelViewSet):     queryset = Item.objects.all()     serializer_class = ItemSerializer 

Configure URLs:

Open myapp/urls.py and configure the URLs for the API:

Python
from django.urls import path, include from rest_framework.routers import DefaultRouter from .views import ItemViewSet  router = DefaultRouter() router.register(r'items', ItemViewSet)  urlpatterns = [     path('', include(router.urls)), ] 

Open myproject/urls.py and include the app URLs:

Python
from django.contrib import admin from django.urls import path, include  urlpatterns = [     path('admin/', admin.site.urls),     path('api/', include('myapp.urls')), ] 

Run the Server:

python manage.py runserver

At this point, you should be able to visit http://127.0.0.1:8000/api/items/ and see the browsable API interface.

admin

Step 2: Disable the Browsable API

Before Disable Admin-Style Browsable Interface:

To disable the browsable API, we need to modify the settings in myproject/settings.py. Specifically, we need to change the DEFAULT_RENDERER_CLASSES setting in the REST_FRAMEWORK configuration.

Modify settings.py:

Open myproject/settings.py and add or update the REST_FRAMEWORK settings:

REST_FRAMEWORK = {
'DEFAULT_RENDERER_CLASSES': (
'rest_framework.renderers.JSONRenderer',
),
}

Restart the Server:

python manage.py runserver

After Disable Admin-Style Browsable Interface:

After making this change, if you visit http://127.0.0.1:8000/api/items/, you will no longer see the browsable API interface. Instead, you will get a JSON response directly.

admin1

Conclusion

The browsable API in Django REST Framework is an excellent tool for development and debugging, providing a convenient interface for testing and interacting with your API. However, in a production environment, it is often advisable to disable this feature for security and performance reasons. By modifying the DEFAULT_RENDERER_CLASSES setting, you can easily disable the admin-style browsable interface and ensure that your API only returns JSON responses.


Next Article
Browsable API in Django REST Framework

K

kasoti2002
Improve
Article Tags :
  • Python
  • Python Django
Practice Tags :
  • python

Similar Reads

  • Browsable API in Django REST Framework
    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. It helps us to use we
    8 min read
  • Adding Permission in API - Django REST Framework
    There are many different scenarios to consider when it comes to access control. Allowing unauthorized access to risky operations or restricted areas results in a massive vulnerability. This highlights the importance of adding permissions in APIs.   Django REST framework allows us to leverage permiss
    7 min read
  • Adding Pagination in APIs - Django REST Framework
    Imagine you have huge amount of details in your database. Do you think that it is wise to retrieve all at once while making an HTTP GET request? Here comes the importance of the Django REST framework pagination feature. It facilitates splitting the large result set into individual pages of data for
    8 min read
  • Django REST Framework: Adding Additional Field to ModelSerializer
    Django REST Framework (DRF) is a powerful and flexible toolkit for building Web APIs in Django. One of its key features is the ModelSerializer class, which provides a shortcut for creating serializers that deal with Django model instances and querysets. However, there are times when you may need to
    3 min read
  • Function based Views - Django Rest Framework
    Django REST Framework allows us to work with regular Django views. It facilitates processing the HTTP requests and providing appropriate HTTP responses. In this section, you will understand how to implement Django views for the Restful Web service. We also make use of the @api_view decorator. Before
    13 min read
  • DictField in serializers - Django REST Framework
    In Django REST Framework the very concept of Serializing is to convert DB data to a datatype that can be used by javascript. Every serializer comes with some fields (entries) which are going to be processed. For example if you have a class with name Employee and its fields as Employee_id, Employee_n
    4 min read
  • Integrating Django with Reactjs using Django REST Framework
    In this article, we will learn the process of communicating between the Django Backend and React js frontend using the Django REST Framework. For the sake of a better understanding of the concept, we will be building a Simple Task Manager and go through the primary concepts for this type of integrat
    15+ min read
  • How to Create a basic API using Django Rest Framework ?
    Django REST Framework is a wrapper over the default Django Framework, basically used to create APIs of various kinds. There are three stages before creating an API through the REST framework, Converting a Model's data to JSON/XML format (Serialization), Rendering this data to the view, and Creating
    4 min read
  • Concrete GenericAPIViews in Django Rest Framework.
    Django Rest Framework (DRF) provides powerful tools for building RESTful APIs in Django projects. One of the key components of DRF is Concrete GenericAPIViews, which offer pre-implemented views for common CRUD (Create, Read, Update, Delete) operations. In this article, we will see Concrete GenericAP
    2 min read
  • Render Model in Django Admin Interface
    Rendering model in admin refers to adding the model to the admin interface so that data can be manipulated easily using admin interface. Django's ORM provides a predefined admin interface that can be used to manipulate data by performing operations such as INSERT, SEARCH, SELECT, CREATE, etc. as in
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences