A comprehensive Django application that enables teachers to create attendance sessions with time-limited QR codes that students scan to mark their presence. The system prevents duplicate scans, provides role-based access control, and offers robust reporting with CSV export capabilities.
- ✅ QR Code Generation: Unique, time-limited QR codes for each attendance session
- ✅ Mobile-First Design: Responsive interface optimized for mobile devices
- ✅ Duplicate Prevention: Database-level constraints prevent duplicate attendance
- ✅ Role-Based Access: Teacher/admin-only session creation with proper permissions
- ✅ HTML5 QR Scanner: In-browser camera scanning with manual entry fallback
- ✅ Real-Time Updates: Live attendance count with auto-refresh
- ✅ CSV Export: Download attendance reports with flexible filtering
- ✅ Session Management: Time-limited sessions with manual close option
- ✅ Comprehensive Reports: Filter by date, session, student with quick presets
- ✅ REST API: Full API for programmatic access
- ✅ Security: CSRF protection, token expiration, IP logging
- Backend: Django 4.2, Django REST Framework
- Frontend: Bootstrap 5, HTML5 QR Code Scanner
- Database: SQLite (development), PostgreSQL/MySQL (production)
- QR Generation: python-qrcode with PIL
- Python 3.8 or higher
- pip (Python package manager)
-
Clone or navigate to the project directory:
cd "c:\Users\yousu\OneDrive\Desktop\Qr Attendence"
-
Create a virtual environment (recommended):
python -m venv venv # Windows venv\Scripts\activate # macOS/Linux source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Configure environment variables:
- Copy
.env.exampleto.env - Update the values as needed (SECRET_KEY, DEBUG, etc.)
- Copy
-
Run database migrations:
python manage.py makemigrations python manage.py migrate
-
Create a superuser (admin account):
python manage.py createsuperuser
-
Load sample data (optional):
python manage.py loaddata fixtures/sample_data.json
Sample credentials:
- Admin:
admin/admin(change in production!) - Teacher:
teacher1/teacher1
- Admin:
-
Run the development server:
python manage.py runserver
-
Access the application:
- Main site: http://127.0.0.1:8000/
- Admin panel: http://127.0.0.1:8000/admin/
- API: http://127.0.0.1:8000/api/
- Login at
/admin/login/with your credentials - Create a Session:
- Go to the Teacher Dashboard
- Click "Create New Session"
- Fill in session details (title, classroom, date)
- Click "Create Session"
- Display QR Code:
- Click "View QR Code" on the session
- Display the QR code to students (projector/screen)
- Monitor live attendance count
- Close Session:
- Click "Close Session" when done
- Or let it expire automatically after 2 hours
- Scan QR Code:
- Open the QR scan URL on your phone
- Allow camera access
- Click "Start Camera" and scan the QR code
- OR enter your Student ID manually
- Confirmation:
- You'll see a success message
- Duplicate scans are prevented
- Go to Reports page
- Apply filters:
- Select specific session
- Choose date range (or use quick filters: Today/Week/Month)
- Filter by student
- Click Export to CSV to download
Most endpoints require authentication. Use Django session authentication or token-based auth.
GET /api/sessions/- List all sessionsPOST /api/sessions/- Create new session (teacher/admin only)GET /api/sessions/{id}/- Get session detailsPOST /api/sessions/{id}/close/- Close sessionGET /api/sessions/{id}/qr_code/- Get QR code imageGET /api/sessions/{id}/attendance/- Get attendance for session
GET /api/attendance/- List attendance records- Query params:
session,student,start_date,end_date
- Query params:
GET /api/attendance/export_csv/- Export to CSVPOST /scan/{token}/- Mark attendance (public endpoint)
GET /api/students/- List studentsGET /api/classrooms/- List classroomsGET /api/teachers/- List teachers
Create a session:
curl -X POST http://localhost:8000/api/sessions/ \
-H "Content-Type: application/json" \
-H "X-CSRFToken: YOUR_CSRF_TOKEN" \
-d '{
"title": "Morning Lecture",
"classroom": 1,
"session_date": "2025-12-01"
}'Mark attendance:
curl -X POST http://localhost:8000/scan/{TOKEN}/ \
-d "student_id=STU001"Run the comprehensive test suite:
# Run all tests
python manage.py test attendance
# Run specific test file
python manage.py test attendance.tests.test_models
# Run with verbosity
python manage.py test attendance --verbosity=2
# Run with coverage (install coverage first: pip install coverage)
coverage run --source='attendance' manage.py test attendance
coverage report-
Environment Variables:
- Set
DEBUG=False - Generate strong
SECRET_KEY - Configure
ALLOWED_HOSTS
- Set
-
Database:
- Switch to PostgreSQL or MySQL
- Update
DATABASE_URLin.env
-
Static Files:
python manage.py collectstatic
-
Security:
- Enable HTTPS
- Configure CORS properly
- Set up rate limiting
- Regular backups
# Install Heroku CLI and login
heroku create your-app-name
heroku addons:create heroku-postgresql:hobby-dev
# Set environment variables
heroku config:set SECRET_KEY="your-secret-key"
heroku config:set DEBUG=False
# Deploy
git push heroku main
heroku run python manage.py migrate
heroku run python manage.py createsuperuser- Connect your GitHub repository
- Add PostgreSQL database
- Set environment variables
- Deploy automatically
- Install dependencies: Python, PostgreSQL, Nginx, Gunicorn
- Clone repository
- Set up virtual environment
- Configure Gunicorn and Nginx
- Set up systemd service
- Enable SSL with Let's Encrypt
qr_attendance/
├── attendance/ # Main Django app
│ ├── models.py # Database models
│ ├── views.py # API and template views
│ ├── serializers.py # DRF serializers
│ ├── permissions.py # Custom permissions
│ ├── utils.py # Utility functions
│ ├── admin.py # Admin configuration
│ ├── urls.py # App URL routing
│ └── tests/ # Test suite
│ ├── test_models.py
│ ├── test_views.py
│ └── test_utils.py
├── qr_attendance/ # Project settings
│ ├── settings.py # Django settings
│ ├── urls.py # Main URL routing
│ └── wsgi.py
├── templates/ # HTML templates
│ ├── base.html
│ ├── dashboard.html
│ ├── teacher_dashboard.html
│ ├── session_qr.html
│ ├── scan_page.html
│ └── reports.html
├── static/ # Static files
│ ├── css/
│ │ └── styles.css
│ └── js/
├── fixtures/ # Sample data
│ └── sample_data.json
├── requirements.txt # Python dependencies
├── .env.example # Environment template
├── .gitignore
└── README.md
- Token Expiration: Sessions expire after 2 hours (configurable)
- Duplicate Prevention: Database constraints prevent duplicate attendance
- CSRF Protection: All forms protected with CSRF tokens
- IP Logging: Track IP addresses for audit trail
- Permission Checks: Role-based access for session management
- Input Validation: All inputs validated and sanitized
QR Scanner not working:
- Ensure HTTPS is enabled (camera requires secure context)
- Check browser camera permissions
- Use manual entry as fallback
Database errors:
- Run migrations:
python manage.py migrate - Check database connection in
.env
Static files not loading:
- Run
python manage.py collectstatic - Check
STATIC_ROOTandSTATIC_URLsettings
Permission denied errors:
- Ensure user has teacher profile or is staff/admin
- Check
IsTeacherOrAdminpermission class
- Fork the repository
- Create a feature branch
- Make your changes
- Write/update tests
- Submit a pull request
This project is open source and available under the MIT License.
For issues, questions, or contributions:
- Create an issue on GitHub
- Contact: admin@example.com
- Initial release
- QR code generation and scanning
- Session management
- Attendance tracking with duplicate prevention
- CSV export
- Mobile-responsive UI
- Comprehensive test suite