A Django REST Framework-based backend API for task management with user authentication. This project provides a robust foundation for building task management applications with secure user registration, login, and token-based authentication.
-
User Authentication System
- User registration with email and password confirmation
- Secure user login with token-based authentication
- Token-based API authentication using Django REST Framework
- Password validation and security checks
-
RESTful API Design
- Clean and intuitive API endpoints
- JSON responses for easy frontend integration
- Proper HTTP status codes and error handling
- Django REST Framework integration
-
Security Features
- Token-based authentication
- Password confirmation validation
- Django's built-in security middleware
- CSRF protection
- Backend Framework: Django 5.2.6
- API Framework: Django REST Framework
- Database: SQLite (development)
- Authentication: Token-based authentication
- Python Version: Compatible with Python 3.8+
Before running this project, make sure you have the following installed:
- Python 3.8 or higher
- pip (Python package installer)
- Git (for cloning the repository)
git clone <repository-url>
cd Task_Management_backend# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activatepip install -r requirements.txt# Navigate to the api directory
cd api
# Run database migrations
python manage.py makemigrations
python manage.py migrate
# Create a superuser (optional)
python manage.py createsuperuserpython manage.py runserverThe API will be available at http://127.0.0.1:8000/
http://127.0.0.1:8000/auth/
- GET
/auth/ - Description: Welcome endpoint with API information
- Authentication: Not required
- Response:
{
"message": "Hi welcome the authentication api v1 here you can make register, login you can register using username, email and password and you can login using username and password"
}- POST
/auth/register - Description: Register a new user account
- Authentication: Not required
- Request Body:
{
"username": "your_username",
"email": "your_email@example.com",
"password": "your_password",
"confirmation": "your_password"
}- Response (Success):
{
"token": "your_auth_token_here",
"message": "User created successfully!"
}- POST
/auth/login - Description: Authenticate user and get access token
- Authentication: Not required
- Request Body:
{
"username": "your_username",
"password": "your_password"
}- Response (Success):
{
"token": "your_auth_token_here",
"message": "Logged in successfully"
}This API uses token-based authentication. After successful login or registration, you'll receive an authentication token. Include this token in the Authorization header for protected endpoints:
Authorization: Bearer your_token_here
Task_Management_backend/
βββ api/ # Django project directory
β βββ api/ # Main project configuration
β β βββ __init__.py
β β βββ settings.py # Django settings
β β βββ urls.py # Main URL configuration
β β βββ wsgi.py # WSGI configuration
β β βββ asgi.py # ASGI configuration
β βββ authentication/ # Authentication app
β β βββ models.py # Database models
β β βββ views.py # API views
β β βββ serializers.py # Data serializers
β β βββ urls.py # Authentication URLs
β β βββ auth.py # Custom authentication
β β βββ migrations/ # Database migrations
β βββ db.sqlite3 # SQLite database
β βββ manage.py # Django management script
βββ requirements.txt # Python dependencies
βββ README.md # This file
curl -X POST http://127.0.0.1:8000/auth/register \
-H "Content-Type: application/json" \
-d '{
"username": "testuser",
"email": "test@example.com",
"password": "testpassword123",
"confirmation": "testpassword123"
}'curl -X POST http://127.0.0.1:8000/auth/login \
-H "Content-Type: application/json" \
-d '{
"username": "testuser",
"password": "testpassword123"
}'import requests
# Register
response = requests.post('http://127.0.0.1:8000/auth/register', json={
'username': 'testuser',
'email': 'test@example.com',
'password': 'testpassword123',
'confirmation': 'testpassword123'
})
print(response.json())
# Login
response = requests.post('http://127.0.0.1:8000/auth/login', json={
'username': 'testuser',
'password': 'testpassword123'
})
token = response.json()['token']
print(f"Token: {token}")The project uses python-dotenv for environment variable management. Create a .env file in the project root:
SECRET_KEY=your_secret_key_here
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1Key settings in api/api/settings.py:
- Database: SQLite for development
- Authentication: Token-based authentication
- Time Zone: Africa/Mogadishu
- Language: English (en-us)
- Debug Mode: Enabled for development
-
Security:
- Change the
SECRET_KEYin production - Set
DEBUG=False - Configure proper
ALLOWED_HOSTS - Use environment variables for sensitive data
- Change the
-
Database:
- Consider using PostgreSQL or MySQL for production
- Set up proper database migrations
-
Static Files:
- Configure static file serving for production
- Use a CDN for better performance
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is part of the CS50 Web Development course. Please refer to the course guidelines for usage and distribution.
-
Database Migration Errors:
python manage.py makemigrations authentication python manage.py migrate
-
Token Authentication Issues:
- Ensure you're including the token in the
Authorizationheader - Check that the token format is
Bearer your_token_here
- Ensure you're including the token in the
-
Port Already in Use:
python manage.py runserver 8001
If you encounter any issues or have questions about this project, please:
- Check the troubleshooting section above
- Review the Django REST Framework documentation
- Create an issue in the repository
Happy Coding! π