Django REST Framework Practice Project - Learn RESTful APIs, CRUD operations, and Token Authentication with a complete working example.
- About
- Features
- Tech Stack
- Project Structure
- Installation & Setup
- API Endpoints
- Usage Examples
- Authentication
- Contributing
This is a comprehensive Django REST Framework practice project designed to help you learn:
- RESTful API Development
- CRUD Operations (Create, Read, Update, Delete)
- Token Authentication
- Serializers and Viewsets
- Database Models and Migrations
- Professional Project Structure
Perfect for beginners and intermediate developers who want to master Django REST Framework!
- π Token Authentication - Secure API access
- π CRUD Operations - Full Create, Read, Update, Delete functionality
- π― Two Django Apps -
webappandwebapp2for different use cases - π SQLite Database - Easy to set up and use
- π§ Professional Structure - Industry-standard project organization
- π Well Documented - Clear code comments and examples
- Backend Framework: Django 5.2.3
- API Framework: Django REST Framework 3.16.0
- Database: SQLite3
- Authentication: Token Authentication
- Language: Python 3.x
DRF-Practice-API/
βββ base/ # Main Django Project
β βββ base/ # Django Settings
β β βββ __init__.py
β β βββ settings.py # Project settings
β β βββ urls.py # Main URL configuration
β β βββ asgi.py
β β βββ wsgi.py
β βββ webapp/ # First Django App
β β βββ models.py # Database models
β β βββ views.py # API views
β β βββ serializers.py # Data serialization
β β βββ urls.py # App URL patterns
β β βββ admin.py # Admin interface
β β βββ migrations/ # Database migrations
β βββ webapp2/ # Second Django App
β β βββ models.py # Additional models
β β βββ views.py # More API views
β β βββ serializers.py # Additional serializers
β β βββ urls.py # App URL patterns
β β βββ migrations/ # Database migrations
β βββ manage.py # Django management script
β βββ db.sqlite3 # SQLite database
βββ .gitignore # Git ignore rules
βββ README.md # This file
- Python 3.8 or higher
- pip (Python package installer)
git clone https://github.com/Sani-Yadav/DRF-Practice-API.git
cd DRF-Practice-API# Windows
python -m venv myenv
myenv\Scripts\activate
# macOS/Linux
python3 -m venv myenv
source myenv/bin/activatecd base
pip install django djangorestframeworkpython manage.py makemigrations
python manage.py migratepython manage.py createsuperuserpython manage.py runserverPOST /api/token/- Get authentication tokenPOST /api/token/refresh/- Refresh token
GET /api/webapp/- List all itemsPOST /api/webapp/- Create new itemGET /api/webapp/{id}/- Get specific itemPUT /api/webapp/{id}/- Update itemDELETE /api/webapp/{id}/- Delete item
GET /api/webapp2/- List all itemsPOST /api/webapp2/- Create new itemGET /api/webapp2/{id}/- Get specific itemPUT /api/webapp2/{id}/- Update itemDELETE /api/webapp2/{id}/- Delete item
curl -X POST http://127.0.0.1:8000/api/token/ \
-H "Content-Type: application/json" \
-d '{"username": "your_username", "password": "your_password"}'curl -X POST http://127.0.0.1:8000/api/webapp/ \
-H "Authorization: Token your_token_here" \
-H "Content-Type: application/json" \
-d '{"name": "Test Item", "description": "This is a test item"}'curl -X GET http://127.0.0.1:8000/api/webapp/ \
-H "Authorization: Token your_token_here"curl -X PUT http://127.0.0.1:8000/api/webapp/1/ \
-H "Authorization: Token your_token_here" \
-H "Content-Type: application/json" \
-d '{"name": "Updated Item", "description": "Updated description"}'This project uses Token Authentication for secure API access:
- Get Token: Send POST request to
/api/token/with username and password - Use Token: Include token in Authorization header:
Authorization: Token your_token_here - Refresh Token: Use
/api/token/refresh/to get new token
import requests
# Step 1: Get token
response = requests.post('http://127.0.0.1:8000/api/token/', {
'username': 'your_username',
'password': 'your_password'
})
token = response.json()['access']
# Step 2: Use token for API calls
headers = {'Authorization': f'Token {token}'}
response = requests.get('http://127.0.0.1:8000/api/webapp/', headers=headers)- Start with Models - Understand database structure in
models.py - Learn Serializers - See how data is formatted in
serializers.py - Study Views - Understand API logic in
views.py - Explore URLs - Learn routing in
urls.py - Test APIs - Use the examples above to test endpoints
- Customize Models - Add new fields and relationships
- Extend Serializers - Add validation and custom methods
- Create New Views - Implement custom business logic
- Add Authentication - Implement custom authentication
- Optimize Performance - Add caching and database optimization
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
This project is open source and available under the MIT License.
- Django REST Framework team for the amazing framework
- Django community for excellent documentation
- All contributors who help improve this project
If you have any questions or need help:
- Create an Issue
- Check the Django REST Framework documentation
- Join the Django community
Happy Coding! π
Made with β€οΈ for the Django community