Django REST Part 1 - Building a REST API with Django: The Initial Setup

Published on 3 Jan 2026 Tech Development
image
Photo by Nicola Sagliocco on Unsplash
Disclaimer: This post was created with the assistance of Gemini and/or ChatGPT for informational purposes. While given a quick look over, readers are encouraged to verify key facts independently.

Learn how to initialize a Django REST Framework project from scratch and create your first functional JSON endpoint.

1. Installation and Project Creation

First, create a virtual environment and install the necessary packages.


pip install django djangorestframework
django-admin startproject core .
python manage.py startapp api
        

2. Registering the Framework

Add 'rest_framework' and your new app to the INSTALLED_APPS list in core/settings.py:


INSTALLED_APPS = [
    ...
    'rest_framework',
    'api',
]
        

3. Creating Your First View

In api/views.py, create a simple function-based view using the @api_view decorator.


from rest_framework.decorators import api_view
from rest_framework.response import Response

@api_view(['GET'])
def hello_world(request):
    return Response({"message": "DRF is alive!"})
        

4. Mapping the URL

In core/urls.py, link a path to your new view:


from django.urls import path
from api import views as api_views

urlpatterns = [
    path('api/hello/', api_views.hello_world, name='api-hello-world'),
]
        

5. Running the API

Start the development server:

python manage.py runserver 

Open your browser and navigate to the following URL to see your JSON data in the DRF Browsable API interface:

URL: http://127.0.0.1:8000/api/hello/

Comments