A secure, scalable Django web application that implements role-based login authentication using MySQL as the database backend. This project supports user roles like Counsellor, HOD, Accountant, and Principal, and redirects each to a custom dashboard after login. Perfect for college or institutional admission workflows, internal panels, or any system requiring controlled role access.
- Role-based authentication using Django’s built-in
Usermodel - Extend user data with a custom
UserProfilemodel - Secure login with role detection and dashboard redirection
- Role & user management via the Django Admin Panel
- MySQL integration for production-ready relational storage
- Environment variables for configuration using
python-decouple - Clean, modular app structure for easy scalability
| File | Purpose |
|---|---|
.env |
Stores environment variables like DB_NAME, DB_USER, SECRET_KEY. Not tracked by Git (sensitive info). |
.gitignore |
Tells Git which files/folders to ignore (e.g. __pycache__, .env, *.pyc). |
manage.py |
Command-line utility to run/manage your Django project (e.g. runserver, migrate, createsuperuser). |
README.md |
Markdown file for project documentation on GitHub. |
| File | Purpose |
|---|---|
__init__.py |
Marks the folder as a Python package. |
settings.py |
Django project settings (installed apps, DB config, middleware, etc). |
urls.py |
Root URL routing configuration. Includes URLs from the users app. |
asgi.py / wsgi.py |
Entry points for serving the app with ASGI/WSGI servers in production. Leave untouched for now. |
| File | Purpose |
|---|---|
__init__.py |
Marks the users folder as a Python package. |
admin.py |
Registers UserProfile in Django Admin to assign roles to users. |
apps.py |
Django app config. Auto-generated. Rarely changed. |
decorators.py |
Custom decorators like @role_required to restrict access by user role. |
forms.py |
Contains LoginForm or any future custom forms. |
models.py |
Defines UserProfile model for storing roles (counsellor, hod, etc.). |
signals.py |
Automatically creates a UserProfile when a User is created (via Django signals). |
tests.py |
Placeholder for unit tests. You can ignore for now unless writing tests. |
urls.py |
Routes app-specific URLs like /user/login. Included in main urls.py. |
views.py |
Handles requests/responses. Contains login logic and role-based redirection. |
git clone https://github.com/yourusername/rolebasedlogin.git cd rolebasedlogin
Create a .env file in the root directory with your database credentials:
DB_NAME=your_db_name
DB_USER=your_username
DB_PASSWORD=your_password
DB_HOST=localhost
DB_PORT=3306
pip install Django mysqlclient python-decouple
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
python manage.py runserver
Visit: http://localhost:8000/user/
Each user must be assigned a role through the Django Admin Panel.
| Role | URL Path | Access Page |
|---|---|---|
| Counsellor | /user/counsellor_dashboard/ |
Student enquiry & basic form |
| HOD | /user/hod_dashboard/ |
Department-level decisions |
| Accountant | /user/accountant_dashboard/ |
Payment verification |
| Principal | /user/principal_dashboard/ |
Final approval & admission print |
- Admin creates a user in the Django Admin Panel.
- A UserProfile is auto-generated via signals.
- Admin assigns a role (e.g., counsellor, hod).
- On login, user is authenticated and redirected to a role-specific dashboard.
Use the @role_required(['role1', 'role2']) decorator to restrict views:
@role_required(['hod'])
def hod_dashboard(request):
Pull requests are welcome! If you have ideas for new features or want to improve role handling, fork the repo and submit a PR.