Skip to content

shivamgravity/django-blog-backend-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django Blog Backend API

This project implements a robus backend for a Blog application using Django and Django REST Framework (DRF). It features a content management system via the Django Admin panel and exposes the data through a RESTful API.

Project Overview

The goal of this project is to demonstrate how to build a scalable backend architecture with relational database models and API endpoints.

Key Features:

  • Django Admin Interface: A powerful GUI for managing blog posts (Create, Read, Update, Delete).
  • RESTful API: Exposes blog data as JSON via /api/posts/ for external consumption.
  • Database Modeling: Uses Django ORM to define a structured BlogPost schema.
  • Browsable API: Leverages DRF's built-in interface for easy testing and interaction.

Prerequisites

  • Python 3.8+

Setup & Installation

  1. Clone the Repository
    git clone https://github.com/shivamgravity/django-blog-backend-api
    cd django-app
  2. Set Up Virtual Environment
    # Create venv
    python -m venv venv
    
    # Activate venv (Windows)
    venv\Scripts\activate
    
    # Activate venv (Mac/Linux)
    source venv/bin/activate
  3. Install Dependencies
    pip install django djangorestframework
  4. Initialize Database
    python manage.py makemigrations
    python manage.py migrate
  5. Create Admin User
    python manage.py createsuperuser

How to Run

  1. Start the Server:
    python manage.py runserver
  2. Access the Admin Panel:
    • Go to http://127.0.0.1:8000/admin
    • Log in with your superuser credentials.
    • You can add, edit, and delete blog posts here.
  3. Access the API:
    • Go to http://127.0.0.1:8000/api/posts/
    • You will see the JSON representation of your blog posts.

Solution Architecture

This project follows the MVT (Model-View-Template) architecture standard in Django, extended with a Serializer layer for the API.

  • Model (models.py): Defines teh BlogPost structure (title, content, created_at). Django ORM maps this to a SQL database table.
  • Serializer (serializers.py): Converts the complex BlogPost model instances into native Python datatypes (JSON) for the API.
  • View (views.py): Uses DRF's ModelViewSet to handle the logic for all CRUD operations (Create, Retrieve, Update, Delete) automatically.
  • URLConf (urls.py): Routes incoming HTTP requests to the appropriate view logic.

API Endpoints

Method Endpoints Description
GET /api/posts/ List all blog posts
POST /api/posts/ Create a new blog post
GET /api/posts/<id>/ Retrieve a specific post
PUT /api/posts/<id>/ Update a specific post
DELETE /api/posts/<id>/ Delete a specific post

About

This demo project demonstrate how to build a scalable backend architecture with relational database models and API endpoints.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages