A Django REST API for managing student records with user authentication and admin capabilities.
- ✅ Student CRUD operations
- ✅ User registration and authentication
- ✅ JWT token-based authentication
- ✅ Admin user management
- ✅ Interactive API documentation (Swagger/Redoc)
- ✅ Comprehensive error handling
- Backend: Django 5.2.7
- API: Django REST Framework 3.16.1
- Authentication: djangorestframework-simplejwt 5.5.1
- Documentation: drf-spectacular 0.28.0
- Database: SQLite (default)
Project/
├── api/ # API app (views, serializers, URLs)
│ ├── views.py # API endpoints
│ ├── serializers.py # DRF serializers
│ ├── urls.py # API routes
│ └── models.py
├── students/ # Students app (models)
│ ├── models.py # Student model
│ ├── views.py
│ └── migrations/
├── django_rest_main/ # Project settings
│ ├── settings.py # Django configuration
│ ├── urls.py # Main URL router
│ └── wsgi.py
├── manage.py # Django CLI
├── requirements.txt # Python dependencies
├── .gitignore # Git ignore rules
├── .env.example # Environment variables template
└── README.md # This file
- Python 3.8+
- pip
-
Clone the repository
git clone https://github.com/yourusername/django-student-api.git cd django-student-api -
Create a virtual environment
# Windows python -m venv env env\Scripts\activate # macOS/Linux python3 -m venv env source env/bin/activate
-
Install dependencies
pip install -r requirements.txt
-
Create environment file
cp .env.example .env
Edit
.envand update settings as needed. -
Run migrations
python manage.py migrate
-
Create superuser (admin)
python manage.py createsuperuser
-
Run development server
python manage.py runserver
The API will be available at:
http://localhost:8000/api/
GET /api/students/- Get all studentsPOST /api/students/- Create a new studentGET /api/students/<id>/- Get student detailPUT /api/students/<id>/- Update student (coming soon)DELETE /api/students/<id>/- Delete student (coming soon)
POST /api/register/- Register new userPOST /api/token/- Get JWT tokenPOST /api/token/refresh/- Refresh JWT token
GET /api/users/- Get all users (admin only)POST /api/users/- Create user (admin only)
- Swagger UI:
http://localhost:8000/api/schema/swagger-ui/ - Redoc:
http://localhost:8000/api/schema/redoc/ - OpenAPI Schema:
http://localhost:8000/api/schema/
curl -X POST http://localhost:8000/api/register/ \
-H "Content-Type: application/json" \
-d '{"username":"john","email":"john@example.com","password":"secure123"}'curl http://localhost:8000/api/students/curl -X POST http://localhost:8000/api/students/ \
-H "Content-Type: application/json" \
-d '{"student_id":"S001","name":"John Doe","branch":"CS"}'Create a .env file based on .env.example:
SECRET_KEY=your-secret-key-here
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1
DATABASE_URL=sqlite:///db.sqlite3
python manage.py makemigrations
python manage.py migratepython manage.py testpython manage.py collectstaticBefore deploying to production:
- Set
DEBUG=Falsein settings - Update
ALLOWED_HOSTSwith your domain - Use a strong
SECRET_KEY - Use PostgreSQL instead of SQLite
- Configure CORS if needed
- Set up proper logging
- Use environment variables for sensitive data
Contributions are welcome! Please follow these steps:
- 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 licensed under the MIT License - see the LICENSE file for details.
For support, email your-email@example.com or open an issue on GitHub.
- Add PUT/PATCH endpoints for student updates
- Add DELETE endpoints for student removal
- Add filtering and search capabilities
- Add pagination
- Add rate limiting
- Add comprehensive test suite
- Add Docker configuration
- Add CI/CD pipeline
Made with ❤️ using Django REST Framework