A comprehensive Django-based web application for tracking student attendance using face recognition and geo-fencing technology. The system ensures students are physically present within designated geographic boundaries when marking attendance.
- Multi-Role Authentication: Support for Student, Staff, and Admin roles with different access levels
- Face Recognition: CNN-based facial verification using OpenCV and face_recognition library
- Geo-Fencing: GPS-based location verification using polygon algorithms and Google Maps API
- Real-time Dashboard: Live attendance monitoring and analytics for all user roles
- Class Management: Create, edit, and manage classes with student enrollment
- Attendance Analytics: Comprehensive reports and visualizations using Chart.js
- Register with face image capture
- View enrolled classes and schedules
- Mark attendance with face and location verification
- View attendance history
- Interactive map display showing class locations
- Staff dashboard with class overview
- Create and manage classes
- Student enrollment management
- Geo-fence creation and management using Google Maps
- Monitor attendance in real-time
- Generate attendance reports
- Full system access and user management
- System analytics and performance metrics
- Attendance analytics and reporting
- Geo-fence management across all classes
- User role assignment and permissions
- Python 3.8+ - Programming language
- Django 3.1.12 - Web framework
- Djongo 1.3.7 - MongoDB connector for Django
- PyMongo 3.11.4 - MongoDB driver
- Django REST Framework 3.11.2 - API framework
- Django CORS Headers 3.10.1 - CORS support
- MongoDB - NoSQL database for flexible data storage
- GridFS - File storage system (for media files)
- OpenCV 4.8.0+ - Computer vision library
- NumPy 1.24.0+ - Numerical computing
- Pillow 10.0.0+ - Image processing
- face_recognition - Face detection and recognition library
- HTML5/CSS3 - Semantic markup and styling
- JavaScript (ES6+) - Interactive functionality
- Bootstrap 5 - Responsive UI framework
- Google Maps JavaScript API - Mapping and location services
- Chart.js - Analytics visualization
- python-decouple 3.8+ - Environment variable management
- requests 2.31.0+ - HTTP library
GAS/
โโโ attendance_system/ # Main project settings
โ โโโ __init__.py
โ โโโ settings.py # Django settings with MongoDB config
โ โโโ urls.py # Main URL configuration
โ โโโ wsgi.py # WSGI configuration
โ โโโ asgi.py # ASGI configuration
โ
โโโ userview/ # Student and general user app
โ โโโ __init__.py
โ โโโ apps.py
โ โโโ models.py # User, Class, GeoFence, Attendance models
โ โโโ forms.py # Registration and login forms
โ โโโ views.py # Authentication and student views
โ โโโ urls.py # App URL configuration
โ โโโ admin.py # Django admin configuration
โ โโโ migrations/ # Database migrations
โ
โโโ adminview/ # Staff and admin app
โ โโโ __init__.py
โ โโโ apps.py
โ โโโ forms.py # Class and geo-fence management forms
โ โโโ views.py # Staff and admin views
โ โโโ urls.py # App URL configuration
โ
โโโ templates/ # HTML templates
โ โโโ base.html # Base template
โ โโโ userview/ # User templates
โ โ โโโ login.html
โ โ โโโ register.html
โ โ โโโ student_home.html
โ โโโ adminview/ # Admin templates
โ โโโ staff_home.html
โ โโโ admin_dashboard.html
โ โโโ class_list.html
โ โโโ class_form.html
โ โโโ geofence_list.html
โ โโโ geofence_form.html
โ โโโ class_enrollment.html
โ โโโ attendance_analytics.html
โ
โโโ static/ # Static files (CSS, JS, images)
โโโ media/ # User-uploaded files
โ โโโ profiles/ # User profile pictures
โ โโโ faces/ # Face recognition data
โ
โโโ TEST/ # Test files and documentation
โ โโโ README.md
โ โโโ PROJECT_SCHEMA.md
โ โโโ test_basic_setup.py
โ โโโ test_face_recognition.py
โ โโโ test_google_maps.py
โ โโโ test_maps.html
โ
โโโ requirements.txt # Python dependencies
โโโ manage.py # Django management script
โโโ config.env.example # Environment variables template
โโโ PROJECT_ARCHITECTURE.md # Detailed architecture documentation
โโโ README.md # This file
- Python 3.8 or higher
- MongoDB 4.4 or higher (running locally or remote)
- Google Maps API key (for geo-fencing functionality)
- Git (for cloning the repository)
git clone <repository-url>
cd GAS# 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.txtNote: If you encounter issues installing dlib (required for face_recognition), you may need to install it separately:
# On Windows (using conda)
conda install -c conda-forge dlib
# On macOS/Linux
# Install cmake first
sudo apt-get install cmake # Ubuntu/Debian
brew install cmake # macOS
pip install dlib-
Install MongoDB on your system:
- Windows: Download from MongoDB Download Center
- macOS:
brew install mongodb-community - Linux: Follow MongoDB Installation Guide
-
Start MongoDB service:
# Windows net start MongoDB # macOS/Linux sudo systemctl start mongod # or mongod
-
Verify MongoDB is running:
mongosh # or mongo
-
Copy the example environment file:
cp config.env.example .env
-
Edit
.envfile with your configuration:# Django Settings SECRET_KEY=your-secret-key-here-change-this-in-production DEBUG=True # Database Settings DB_NAME=attendance_system DB_HOST=localhost DB_PORT=27017 DB_USERNAME= DB_PASSWORD= # Google Maps API GOOGLE_MAPS_API_KEY=your-google-maps-api-key-here # Face Recognition Configuration FACE_RECOGNITION_TOLERANCE=0.6 FACE_RECOGNITION_MODEL=hog GEO_FENCING_BUFFER=10
-
Get Google Maps API Key:
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable "Maps JavaScript API" and "Geocoding API"
- Create credentials (API Key)
- Add the API key to your
.envfile
# Create migrations
python manage.py makemigrations
# Apply migrations
python manage.py migratepython manage.py createsuperuserFollow the prompts to create an admin user.
python manage.py collectstatic --noinputpython manage.py runserverThe application will be available at http://localhost:8000
-
Registration:
- Navigate to the registration page
- Fill in username, email, password, and role (student)
- Allow camera access when prompted
- Capture face image for face recognition
- Submit registration
-
Login:
- Enter username and password
- Access student dashboard
-
Mark Attendance:
- View enrolled classes on the dashboard
- Select a class to mark attendance
- Enable camera for face recognition
- Allow location access for GPS verification
- Click "Mark Attendance" button
- System verifies face and location
- Attendance is recorded if both checks pass
-
View Attendance History:
- Check attendance records on the dashboard
- View attendance statistics
-
Login: Access staff dashboard with staff/admin credentials
-
Class Management:
- Create new classes
- Edit existing classes
- Delete classes
- View all classes
-
Student Enrollment:
- Select a class
- Add/remove students from enrollment
- View enrolled students
-
Geo-fence Management:
- Create geo-fences using Google Maps drawing tools
- Draw polygon boundaries on the map
- Assign geo-fences to classes
- Edit or delete geo-fences
-
Attendance Monitoring:
- View real-time attendance for classes
- Monitor student attendance status
- Generate attendance reports
-
Login: Access admin dashboard
-
User Management:
- View all users
- Create/edit user accounts
- Assign roles (student, staff, admin)
- Manage user permissions
-
System Analytics:
- View comprehensive attendance analytics
- Monitor system performance
- Generate reports
-
Geo-fence Management:
- Manage all geo-fences across the system
- View geo-fence usage statistics
GET /- Login pagePOST /login/- User loginPOST /register/- User registrationGET /logout/- User logout
GET /student-home/- Student dashboardPOST /mark-attendance/<class_id>/- Mark attendance for a classGET /profile/- User profile (if implemented)
GET /adminview/staff-home/- Staff dashboardGET /adminview/admin-dashboard/- Admin dashboardGET /adminview/classes/- List all classesPOST /adminview/classes/create/- Create new classGET /adminview/classes/<id>/update/- Edit classPOST /adminview/classes/<id>/delete/- Delete classGET /adminview/classes/<id>/enrollment/- Manage class enrollmentGET /adminview/geofences/- List all geo-fencesPOST /adminview/geofences/create/- Create new geo-fenceGET /adminview/geofences/<id>/update/- Edit geo-fencePOST /adminview/geofences/<id>/delete/- Delete geo-fenceGET /adminview/attendance-analytics/- Attendance analytics
- CSRF Protection: Built-in Django CSRF tokens
- Session Management: Secure session handling with configurable timeout
- Input Validation: Form validation and data sanitization
- Role-based Access Control: Different permissions for different user roles
- Secure Authentication: Django's built-in authentication system
- Password Validation: Strong password requirements
- CORS Configuration: Configurable cross-origin resource sharing
The project includes test files in the TEST/ directory:
# Run basic setup test
python TEST/test_basic_setup.py
# Test face recognition
python TEST/test_face_recognition.py
# Test Google Maps integration
python TEST/test_google_maps.py-
Face Recognition Not Working
- Ensure OpenCV and dlib are properly installed
- Check camera permissions in browser
- Verify face image quality during registration
- Ensure good lighting conditions
-
Location Not Detected
- Enable location services in browser
- Check HTTPS requirement for geolocation (some browsers require HTTPS)
- Verify GPS permissions
- Test location access in browser console
-
MongoDB Connection Issues
- Ensure MongoDB service is running
- Check connection string in
.envfile - Verify database credentials
- Check MongoDB logs for errors
-
Google Maps Not Loading
- Check API key configuration in
.env - Verify API key has proper permissions (Maps JavaScript API enabled)
- Check billing status for Google Cloud project
- Verify API key restrictions (if any)
- Check API key configuration in
-
Djongo Errors
- Ensure MongoDB is running
- Check database name matches in settings
- Some complex Django ORM queries may not work with djongo - use raw queries if needed
-
Static Files Not Loading
- Run
python manage.py collectstatic - Check
STATIC_URLandSTATIC_ROOTin settings - Verify static files directory exists
- Run
Set DEBUG=True in .env file for detailed error messages and debugging information. Never use DEBUG=True in production!
- Extends Django's AbstractUser
- Fields: username, email, password, role, department_id, face_data (JSON)
- Roles: student, staff, admin
- Fields: name, staff (ForeignKey), geolocation (ForeignKey to GeoFence), students (ManyToMany)
- Relationships: One staff member, many students, one geo-fence
- Fields: name, coordinates (JSON array of {lat, lng}), created_at, updated_at
- Methods:
is_point_inside(lat, lng)- Point-in-polygon algorithm
- Fields: student, class_instance, timestamp, is_present, geolocation, face_verified, location_verified
- Unique constraint: student + class_instance + timestamp
- Environment Variables: Use secure environment variables, never commit
.envfile - SECRET_KEY: Generate a new secret key for production
- DEBUG: Set
DEBUG=Falsein production - ALLOWED_HOSTS: Configure properly in settings
- Database: Use production MongoDB instance or cluster
- Static Files: Configure proper static file serving (Nginx, AWS S3, etc.)
- Media Files: Use cloud storage (AWS S3, Google Cloud Storage)
- HTTPS: Enable HTTPS for geolocation API to work properly
- Security: Review Django security checklist
- Monitoring: Set up logging and monitoring
- Web Server: Nginx
- Application Server: Gunicorn or uWSGI
- Database: MongoDB Atlas (cloud) or self-hosted MongoDB cluster
- File Storage: AWS S3 or Google Cloud Storage
- Process Manager: Supervisor or systemd
- Reverse Proxy: Nginx
FACE_RECOGNITION_TOLERANCE: Lower values = stricter matching (default: 0.6)FACE_RECOGNITION_MODEL: 'hog' or 'cnn' (default: 'hog')
GEO_FENCING_BUFFER: Buffer zone in meters for GPS accuracy (default: 10)
SESSION_COOKIE_AGE: Session timeout in seconds (default: 3600 = 1 hour)SESSION_EXPIRE_AT_BROWSER_CLOSE: Session expires when browser closes
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Create an issue in the repository
- Contact the development team
- Check the documentation in
PROJECT_ARCHITECTURE.mdandTEST/PROJECT_SCHEMA.md
- Mobile App: Native mobile applications for iOS and Android
- Real-time Notifications: Push notifications for attendance updates
- Advanced Analytics: Machine learning insights and predictions
- Multi-language Support: Internationalization (i18n)
- API Documentation: Swagger/OpenAPI documentation
- Comprehensive Testing Suite: Unit tests, integration tests
- Biometric Integration: Additional biometric verification methods
- Offline Mode: Support for offline attendance marking
- Export Features: PDF/Excel export for reports
- Email Notifications: Automated email alerts for attendance
- Architecture Details: See
PROJECT_ARCHITECTURE.md - Schema Documentation: See
TEST/PROJECT_SCHEMA.md - Test Documentation: See
TEST/README.md
Note: This is a development version. Ensure all security measures are in place before deploying to production.