Overview
The Profile Management system allows authenticated users to view and update their personal information, upload custom avatars, and manage their account settings. All profile operations are secured and restricted to the authenticated user.User Profile Model
The user profile is based on Django’sAbstractUser with custom extensions (models.py:5-16):
Basic Info
Username, email, first name, and last name
Contact
Optional phone number field (max 10 characters)
Avatar
Profile picture uploaded to ‘avatars/’ directory
The email field is unique across all users and serves as a primary identifier for authentication.
Viewing Profile Information
Authenticated users can retrieve their complete profile data.API Endpoint
URL:POST /api/users/profile/
Authentication: Required (IsAuthenticated)
Response:
Implementation
The profile view endpoint (views.py:82-92):
Updating Profile Information
Users can update their profile details including personal information and avatar.API Endpoint
URL:PUT /api/users/update-profile/<pk>/
Authentication: Required (IsAuthenticated)
Content-Type: multipart/form-data (for avatar uploads)
Request Body:
Implementation
The update profile endpoint (views.py:95-117):
Partial Updates
The endpoint supports partial updates (partial=True), allowing users to update specific fields without sending the entire profile:
Avatar Support
The system supports profile picture uploads with specific handling.Avatar Upload Process
1
File Selection
User selects an image file through the frontend upload component
2
Multipart Upload
File is sent as multipart/form-data in the PUT request
3
Server Processing
Backend receives file via
request.FILES['avatar']4
Storage
Image is saved to
avatars/ directory in media storage5
URL Generation
Django generates a URL path for accessing the uploaded image
Avatar Upload Component
The frontend includes a dedicated avatar uploader (AvatarUploader.jsx):
Supported Image Formats
TheImageField accepts common image formats:
- JPEG (.jpg, .jpeg)
- PNG (.png)
- GIF (.gif)
- WebP (.webp)
- BMP (.bmp)
Account Deletion
Users can permanently delete their accounts and all associated data.API Endpoint
URL:DELETE /api/users/delete/<user_id>/
Authentication: Required (IsAuthenticated)
Response:
Implementation
The delete user endpoint (views.py:121-129):
Confirmation Flow
Best practice is to implement a confirmation dialog:Profile Features Summary
View Profile
Retrieve complete profile information including avatar URL
Update Info
Modify personal details with partial update support
Upload Avatar
Upload and update profile pictures with multipart support
Delete Account
Permanently remove account and all associated data
Frontend Profile Page
The profile page is implemented with a content component (Content.jsx) that displays and manages profile information:
Authorization Model
Profile management includes multiple layers of authorization:Endpoint-Level Authorization
User-Level Authorization
Automatic User Filtering
Error Handling
Media Configuration
For avatar uploads to work properly, ensure your Django settings include:settings.py
urls.py
In production, serve media files through a CDN or object storage service like AWS S3 rather than directly from Django.
Best Practices
Input Validation
Validate email format, phone number length, and image file types before submission
Image Optimization
Resize images client-side to reduce upload time and storage costs
Error Feedback
Display clear, actionable error messages for validation failures
Confirmation Dialogs
Require confirmation for destructive actions like account deletion
