Student Management System is a system for Students where Students can check their details. In this system, a Admin Panel is included where admin can add students, add faculty and create notices.
Create A Django Project
django-admin startproject sms
Create A App in our project
python manage.py startapp main
Go to Setting.py and install the main app. Also we will add template folder in this file and create a static folder.
TEMPLATES_DIR = BASE_DIR/'templates'
TEMPLATES = [
{
.
.
.
'DIRS': [TEMPLATES_DIR],
.
.
.
},
]
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main'
]
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
Go to Project's urls.py file and include main app urls
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('main.urls'))
]
Let some code in views.py file
from django.shortcuts import render, redirect
from .models import AboutPage, ContactPage, Student, Notice, Teacher
# Create your views here.
def home(request):
publicNotices = Notice.objects.filter(isPublic = True)
data = {"public_notices": publicNotices}
return render(request, 'home.html', data)
def about(request):
about_text = AboutPage.objects.all()
data = {"aboutDetails": about_text}
return render(request, 'about.html', data)
def contact(request):
contact_text = ContactPage.objects.all()
data = {"contactDetails": contact_text}
return render(request, 'contact.html', data)
def adminPanel(request):
if 'admin_user' in request.session:
all_students = Student.objects.all()
all_teachers = Teacher.objects.all()
data = {'students': all_students, 'teachers': all_teachers}
return render(request, 'admin/admin_panel.html', data)
else:
return redirect('admin_login')
def adminLogin(request):
if request.method == 'POST':
admin_email = request.POST['email']
admin_pwd = request.POST['pwd']
if admin_email == "admin@gmail.com" and admin_pwd == "admin@123":
request.session['admin_user'] = admin_email
return redirect('admin_panel')
else:
return redirect('admin_login')
return render(request, 'admin/admin_login.html')
def adminLogout(request):
del request.session['admin_user']
return redirect('admin_login')
def adminAbout(request):
about_details = AboutPage.objects.all()
data = {"aboutDetails": about_details}
return render(request, 'admin/admin_about.html', data)
def updateAbout(request, id):
if request.method == 'POST':
aboutText = request.POST['text']
about_obj = AboutPage.objects.get(id = id)
about_obj.about = aboutText
about_obj.save()
return redirect('admin_about')
def adminContact(request):
contact_details = ContactPage.objects.all()
data = {"contactDetails": contact_details}
return render(request, 'admin/admin_contact.html', data)
def updateContact(request, id):
if request.method == 'POST':
contactAddress = request.POST['address']
contactEmail = request.POST['email']
contactNumber = request.POST['contact']
contact_obj = ContactPage.objects.get(id = id)
contact_obj.address = contactAddress
contact_obj.email = contactEmail
contact_obj.contact_num = contactNumber
contact_obj.save()
return redirect('admin_contact')
def addStudent(request):
if request.method == 'POST':
fullName = request.POST['full_name']
fatherName = request.POST['f_name']
motherName = request.POST['m_name']
gender = request.POST['gender']
address = request.POST['address']
city = request.POST['city']
stuEmail = request.POST['stu_email']
contactNum = request.POST['contact_number']
dob = request.POST['dob']
course = request.POST['course']
studentId = request.POST['stu_id']
studentUserName = request.POST['stu_user_name']
studentPassword = request.POST['stu_pwd']
add_student = Student.objects.create(full_name=fullName, father_name=fatherName, mother_name=motherName, gender=gender, address=address, city=city,email=stuEmail, contact_num=contactNum, date_of_birth=dob, course=course, stu_id=studentId, user_name=studentUserName, password=studentPassword)
add_student.save()
return render(request, 'admin/new_student.html')
def manageStudent(request):
all_students = Student.objects.all()
data = {"students": all_students}
return render(request, 'admin/manage_students.html', data)
def updateStudent(request, id):
if request.method == 'POST':
student_obj = Student.objects.get(id=id)
fullName = request.POST['full_name']
fatherName = request.POST['f_name']
motherName = request.POST['m_name']
gender = request.POST['gender']
address = request.POST['address']
city = request.POST['city']
stuEmail = request.POST['stu_email']
contactNum = request.POST['contact_number']
dob = request.POST['dob'] or student_obj.date_of_birth
course = request.POST['course'] or student_obj.course
studentId = request.POST['stu_id']
studentUserName = request.POST['stu_user_name']
studentPassword = request.POST['stu_pwd']
student_obj.full_name = fullName
student_obj.father_name = fatherName
student_obj.mother_name = motherName
student_obj.gender = gender
student_obj.address = address
student_obj.city = city
student_obj.email = stuEmail
student_obj.contact_num = contactNum
student_obj.date_of_birth = dob
student_obj.course = course
student_obj.stu_id = studentId
student_obj.user_name = studentUserName
student_obj.password = studentPassword
student_obj.save()
return redirect('manage_students')
def deleteStudent(request, id):
if 'admin_user' in request.session:
stu_obj = Student.objects.get(id=id)
stu_obj.delete()
return redirect('manage_students')
def addNotice(request):
if request.method == 'POST':
noticeTitle = request.POST['notice_title']
noticeContent = request.POST['notice_content']
isPublic = request.POST['notice_status']
add_notice = Notice.objects.create(title=noticeTitle, content=noticeContent, isPublic=isPublic)
add_notice.save()
return render(request, "admin/admin_notice.html")
def manageNotices(request):
all_notices = Notice.objects.all()
data = {'notices': all_notices}
return render(request, 'admin/manage_notices.html', data)
def deleteNotice(request, id):
if 'admin_user' in request.session:
notice_obj = Notice.objects.get(id=id)
notice_obj.delete()
return redirect('manage_notices')
def updateNotice(request, id):
if request.method == 'POST':
title = request.POST['title']
content = request.POST['content']
status = request.POST['status']
notice_obj = Notice.objects.get(id=id)
notice_obj.title = title
notice_obj.content = content
notice_obj.isPublic = status
notice_obj.save()
return redirect('manage_notices')
def addTeacher(request):
if request.method == 'POST':
full_name = request.POST['full_name']
gender = request.POST['gender']
email = request.POST['email']
contact_num = request.POST['contact_number']
qualification = request.POST['qualification']
add_teacher = Teacher.objects.create(full_name=full_name, gender=gender, email=email,contact_num=contact_num, qualification=qualification)
add_teacher.save()
return render(request, 'admin/add_teacher.html')
def manageTeachers(request):
all_teachers = Teacher.objects.all()
data = {"teachers": all_teachers}
return render(request, 'admin/manage_teachers.html', data)
def deleteTeacher(request, id):
teacher_obj = Teacher.objects.get(id=id)
teacher_obj.delete()
return redirect('manage_teachers')
def studentLogin(request):
if 'student_user' not in request.session:
if request.method == "POST":
user_name = request.POST['userName']
student_pwd = request.POST['stuPwd']
stu_exists = Student.objects.filter(user_name=user_name, password=student_pwd).exists()
if stu_exists:
request.session['student_user'] = user_name
return redirect('student_dashboard')
return render(request, 'student/student_login.html')
else:
return redirect('student_dashboard')
def studentDashboard(request):
if 'student_user' in request.session:
student_in_session = Student.objects.get(user_name=request.session['student_user'])
data = {"student": student_in_session}
return render(request, 'student/student_dashboard.html', data)
else:
return redirect('student_login')
def studentLogout(request):
del request.session['student_user']
return redirect('student_login')
def updateFaculty(request, id):
if request.method == 'POST':
full_name = request.POST['full_name']
email = request.POST['email']
contactNumber = request.POST['contact_number']
gender = request.POST['gender']
qualification = request.POST['qualification']
teacher_obj = Teacher.objects.get(id=id)
teacher_obj.full_name = full_name
teacher_obj.email = email
teacher_obj.contact_num = contactNumber
teacher_obj.gender = gender
teacher_obj.qualification = qualification
teacher_obj.save()
return redirect('manage_teachers')
def viewNotices(request):
if 'student_user' in request.session:
student_notice = Notice.objects.filter(isPublic = False)
data = {"notices": student_notice}
return render(request, 'student/view_notices.html', data)
else:
return redirect('student_login')
def studentSettings(request):
if 'student_user' in request.session:
student_obj = Student.objects.get(user_name = request.session['student_user'])
data = {'student': student_obj}
if request.method == 'POST':
currentPwd = request.POST['current_pwd']
new_pwd = request.POST['new_pwd']
student_obj.password =new_pwd
student_obj.save()
return redirect('student_dashboard')
return render(request, "student/student_settings.html", data)
else:
return redirect('student_login')
Create some urls in urls.py file
from django.urls import path
from . import views
urlpatterns = [
path('', views.home, name="home"),
path('about/', views.about, name="about"),
path('contact/', views.contact, name="contact"),
path('admin_panel/dashboard', views.adminPanel, name="admin_panel"),
path('admin_panel/login/', views.adminLogin, name="admin_login"),
path('admin_panel/logout/', views.adminLogout, name="admin_logout"),
path('student/login/', views.studentLogin, name="student_login"),
path('admin_panel/add_student/', views.addStudent, name="add_student"),
path('admin_panel/about/', views.adminAbout, name="admin_about"),
path('admin_panel/update_about/<str:id>/', views.updateAbout, name="update_about"),
path('admin_panel/contact/', views.adminContact, name="admin_contact"),
path('admin_panel/update_contact/<str:id>/', views.updateContact, name="update_contact"),
path('admin_panel/manage_students/', views.manageStudent, name="manage_students"),
path('admin_panel/update_student/<str:id>/', views.updateStudent, name="update_student"),
path('admin_panel/delete_student/<str:id>/', views.deleteStudent, name="delete_student"),
path('admin_panel/add_notice/', views.addNotice, name="add_notice"),
path('admin_panel/manage_notices/', views.manageNotices, name="manage_notices"),
path('admin_panel/delete_notice/<str:id>/', views.deleteNotice, name="delete_notice"),
path('admin_panel/update_notice/<str:id>/', views.updateNotice, name="update_notice"),
path('admin_panel/add_teacher/', views.addTeacher, name="add_teacher"),
path('admin_panel/manage_teacher/', views.manageTeachers, name="manage_teachers"),
path('admin_panel/delete_teacher/<str:id>/', views.deleteTeacher, name="delete_teacher"),
path('student/dashboard/', views.studentDashboard, name="student_dashboard"),
path('student/logout/', views.studentLogout, name="student_logout"),
path('student/update_teacher/<str:id>/', views.updateFaculty, name="update_teacher"),
path('student/view_notices/', views.viewNotices, name="view_notices"),
path('student/student_settings/', views.studentSettings, name="student_settings")
]
Let's work on our database where we'll create models in models.py file
from django.db import models
# Create your models here.
class AboutPage(models.Model):
about = models.TextField()
def __str__(self):
return self.about
class ContactPage(models.Model):
address = models.TextField()
contact_num = models.IntegerField()
email = models.EmailField()
def __str__(self):
return self.address
class Student(models.Model):
full_name = models.CharField(max_length=100)
father_name = models.CharField(max_length=100)
mother_name = models.CharField(max_length=100)
gender = models.CharField(max_length=50, default="Male")
address = models.CharField(max_length=100)
city = models.CharField(max_length=50)
email = models.EmailField()
contact_num = models.IntegerField(default=1234567)
date_of_birth = models.DateField()
course = models.CharField(max_length=50)
stu_id = models.CharField(max_length=50)
user_name = models.CharField(max_length=50)
password = models.CharField(max_length=100)
def __str__(self):
return self.full_name
class Notice(models.Model):
title = models.CharField(max_length=200)
content = models.TextField()
isPublic = models.BooleanField(default=False)
def __str__(self):
return self.title
class Teacher(models.Model):
full_name = models.CharField(max_length=100)
gender = models.CharField(max_length=50)
email = models.EmailField()
contact_num = models.CharField(max_length=20)
qualification = models.TextField()
def __str__(self):
return self.full_name
Register these models in admin.py file
from django.contrib import admin
from .models import AboutPage, ContactPage, Student, Notice, Teacher
# Register your models here.
admin.site.register(AboutPage)
admin.site.register(ContactPage)
admin.site.register(Student)
admin.site.register(Notice)
admin.site.register(Teacher)
Now work on our project's templates. In these templates, we will use Django Template Language.
base.html
{% load static %}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SMS</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
</head>
<body>
<header class="p-3 text-bg-dark">
<div class="container">
<div class="d-flex flex-wrap align-items-center justify-content-center justify-content-lg-start">
<a href="/" class="d-flex align-items-center mb-2 mb-lg-0 text-white text-decoration-none">
<svg class="bi me-2" width="40" height="32" role="img" aria-label="Bootstrap"><use xlink:href="#bootstrap"/></svg>
</a>
<ul class="nav col-12 col-lg-auto me-lg-auto mb-2 justify-content-center mb-md-0">
<li><a href="{% url 'home' %}" class="nav-link px-2 text-white">Home</a></li>
<li><a href="{% url 'about' %}" class="nav-link px-2 text-white">About</a></li>
<li><a href="{% url 'contact' %}" class="nav-link px-2 text-white">Contact</a></li>
<li><a href="{% url 'admin_panel' %}" class="nav-link px-2 text-white">Admin</a></li>
<li><a href="{% url 'student_login' %}" class="nav-link px-2 text-white">Student</a></li>
</ul>
<form class="col-12 col-lg-auto mb-3 mb-lg-0 me-lg-3" role="search">
<input type="search" class="form-control form-control-dark text-bg-dark" placeholder="Search..." aria-label="Search">
</form>
</div>
</div>
</header>
{% block body %}
{% endblock %}
<div class="container">
<footer class="py-5">
<div class="row">
<div class="col-6 col-md-2 mb-3">
<h5>Section</h5>
<ul class="nav flex-column">
<li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-muted">Home</a></li>
<li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-muted">Features</a></li>
<li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-muted">Pricing</a></li>
<li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-muted">FAQs</a></li>
<li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-muted">About</a></li>
</ul>
</div>
<div class="col-6 col-md-2 mb-3">
<h5>Section</h5>
<ul class="nav flex-column">
<li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-muted">Home</a></li>
<li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-muted">Features</a></li>
<li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-muted">Pricing</a></li>
<li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-muted">FAQs</a></li>
<li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-muted">About</a></li>
</ul>
</div>
<div class="col-6 col-md-2 mb-3">
<h5>Section</h5>
<ul class="nav flex-column">
<li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-muted">Home</a></li>
<li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-muted">Features</a></li>
<li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-muted">Pricing</a></li>
<li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-muted">FAQs</a></li>
<li class="nav-item mb-2"><a href="#" class="nav-link p-0 text-muted">About</a></li>
</ul>
</div>
<div class="col-md-5 offset-md-1 mb-3">
<form>
<h5>Subscribe to our newsletter</h5>
<p>Monthly digest of what's new and exciting from us.</p>
<div class="d-flex flex-column flex-sm-row w-100 gap-2">
<label for="newsletter1" class="visually-hidden">Email address</label>
<input id="newsletter1" type="text" class="form-control" placeholder="Email address">
<button class="btn btn-primary" type="button">Subscribe</button>
</div>
</form>
</div>
</div>
<div class="d-flex flex-column flex-sm-row justify-content-between py-4 my-4 border-top">
<p>© 2022 Company, Inc. All rights reserved.</p>
<ul class="list-unstyled d-flex">
<li class="ms-3"><a class="link-dark" href="#"><svg class="bi" width="24" height="24"><use xlink:href="#twitter"/></svg></a></li>
<li class="ms-3"><a class="link-dark" href="#"><svg class="bi" width="24" height="24"><use xlink:href="#instagram"/></svg></a></li>
<li class="ms-3"><a class="link-dark" href="#"><svg class="bi" width="24" height="24"><use xlink:href="#facebook"/></svg></a></li>
</ul>
</div>
</footer>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script>
</body>
</html>
about.html
{% extends 'base.html' %}
{% block body %}
<div class="container my-5">
<h2 class="text-center border-bottom">About</h2>
<p>{{aboutDetails.first.about}}</p>
</div>
{% endblock %}
contact.html
{% extends 'base.html' %}
{% block body %}
<style>
table{
width: 100%;
}
table th{
text-align: center;
}
table td{
text-align: center;
padding: 10px;
border: 1px solid;
}
</style>
<div class="container w-100 my-5">
<h1 class="text-center">Contact</h1>
<hr>
<table>
<tr>
<th>
Address
</th>
<th>
Contact Number
</th>
<th>
Email
</th>
</tr>
<tr>
<td>
{{contactDetails.first.address}}
</td>
<td>
{{contactDetails.first.contact_num}}
</td>
<td>
{{contactDetails.first.email}}
</td>
</tr>
</table>
</div>
<hr>
{% endblock %}
home.html
{% extends 'base.html' %}
{% load static %}
{% block body %}
<div id="carouselExampleControls" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<h1 style="position: absolute; top: 300px; left: 200px; color: white;">Welcome to Home</h1>
<a href="{% url 'student_login' %}" style="text-decoration: none; position: absolute; top: 370px; left: 200px; color: white; background-color: blue; padding: 10px; font-weight: bold;">Student Login</a>
<img src="{% static 'images/home3.jpg' %}" class="d-block" style="width: 100%; height: 650px;" alt="...">
</div>
<div class="carousel-item">
<img src="{% static 'images/home1.jpg' %}" class="d-block" style="width: 100%; height: 650px;" alt="...">
</div>
<div class="carousel-item">
<img src="{% static 'images/home.jpg' %}" class="d-block" style="width: 100%; height: 650px;" alt="...">
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
<br><br>
<div class="card text-center">
<div class="card-header">
<h5>Public Notice</h5>
</div>
<div class="card-body">
<h5 class="card-title">{{notice.title}}</h5>
<p class="card-text">{{notice.content}}</p>
<table class="table table-small">
<tr>
<th>Title</th>
<th>Content</th>
</tr>
{% for notice in public_notices %}
<tr>
<td>{{notice.title}}</td>
<td>{{notice.content}}</td>
</tr>
{% endfor %}
</table>
</div>
</div>
{% endblock %}
Let's create a Student folder in template folder where we will store our templates which is related to Students.
- student_base.html
- student_dashboard.html
- student_login.html
- student_settings.html
- view_notices.html
student_base.html
{% extends 'base.html' %}
{% load static %}
{% block body %}
<div id="carouselExampleControls" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<h1 style="position: absolute; top: 300px; left: 200px; color: white;">Welcome to Home</h1>
<a href="{% url 'student_login' %}" style="text-decoration: none; position: absolute; top: 370px; left: 200px; color: white; background-color: blue; padding: 10px; font-weight: bold;">Student Login</a>
<img src="{% static 'images/home3.jpg' %}" class="d-block" style="width: 100%; height: 650px;" alt="...">
</div>
<div class="carousel-item">
<img src="{% static 'images/home1.jpg' %}" class="d-block" style="width: 100%; height: 650px;" alt="...">
</div>
<div class="carousel-item">
<img src="{% static 'images/home.jpg' %}" class="d-block" style="width: 100%; height: 650px;" alt="...">
</div>
</div>
<button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</button>
<button class="carousel-control-next" type="button" data-bs-target="#carouselExampleControls" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</button>
</div>
<br><br>
<div class="card text-center">
<div class="card-header">
<h5>Public Notice</h5>
</div>
<div class="card-body">
<h5 class="card-title">{{notice.title}}</h5>
<p class="card-text">{{notice.content}}</p>
<table class="table table-small">
<tr>
<th>Title</th>
<th>Content</th>
</tr>
{% for notice in public_notices %}
<tr>
<td>{{notice.title}}</td>
<td>{{notice.content}}</td>
</tr>
{% endfor %}
</table>
</div>
</div>
{% endblock %}
student_dashboard.html
{% extends 'student/student_base.html' %}
{% block title %}
Student - Dashboard
{% endblock %}
{% block body %}
<div class="container" style="margin: 100px;">
<h1>Dashboard</h1>
<a href="{% url 'view_notices' %}" class="btn btn-warning" style="float: right; margin-top: -70px;">View Notices</a>
<table class="table">
<tr>
<th>Student Name</th>
<td>{{student.full_name}}</td>
<th>Father's Name</th>
<td>{{student.father_name}}</td>
</tr>
<tr>
<th>Gender</th>
<td>{{student.gender}}</td>
<th>Mother's Name</th>
<td>{{student.mother_name}}</td>
</tr>
<tr>
<th>Contact Number</th>
<td>{{student.contact_num}}</td>
<th>Email</th>
<td>{{student.email}}</td>
</tr>
<tr>
<th>Address</th>
<td>{{student.address}}</td>
<th>City</th>
<td>{{student.city}}</td>
</tr>
<tr>
<th>Student Id</th>
<td>{{student.stu_id}}</td>
<th>Date of Birth</th>
<td>{{student.date_of_birth}}</td>
</tr>
<tr>
<th>Course</th>
<td>{{student.course}}</td>
<th>User Name</th>
<td>{{student.user_name}}</td>
</tr>
</table>
</div>
{% endblock %}
student_login.html
{% extends 'base.html' %}
{% block body %}
<div class="container my-5 w-50">
<h1 class="text-center">Student Login</h1>
<form action="{% url 'student_login' %}" method="post">
{% csrf_token %}
<input type="text" class="form-control" placeholder="Username" name="userName">
<br>
<input type="password" class="form-control" placeholder="Password" name="stuPwd">
<br>
<input type="submit" value="Login" class="btn btn-primary form-control">
</form>
</div>
{% endblock %}
student_settings.html
{% extends 'student/student_base.html' %}
{% block title %}
Student - Settings
{% endblock %}
{% block body %}
<div class="container" style="margin-top: 100px;">
<h2>Settings</h2>
<form action="{% url 'student_settings' %}" method="post">
{% csrf_token %}
<input type="text" value="{{student.user_name}}" name="full_name" class="form-control" placeholder="User Name">
<br>
<input type="text" value="{{student.password}}" name="current_pwd" class="form-control" placeholder="Current Password">
<br>
<input type="password" class="form-control" name="new_pwd" placeholder="New Password">
<br>
<input type="submit" class="form-control btn btn-primary" value="Update">
</form>
</div>
{% endblock %}
view_notices.html
{% extends 'student/student_base.html' %}
{% block title %}
Student-Dashboard - Notices
{% endblock %}
{% block body %}
<div class="container" style="margin: 100px;">
<h1>Notices for Students</h1>
{% if notices %}
<table class="table">
<tr>
<th>S.No</th>
<th>Title</th>
<th>Content</th>
</tr>
{% for notice in notices reversed %}
<tr>
<td>{{forloop.counter}}</td>
<td>{{notice.title}}</td>
<td>{{notice.content}}</td>
</tr>
{% endfor %}
</table>
{% else %}
<h2 class="text-danger mx-5 my-5">Notices are not available.</h2>
{% endif %}
</div>
{% endblock %}
Let's create a Admin folder in Template folder where we will store templates which is related to Admin.
- admin_base.html
- add_teacher.html
- admin_about.html
- admin_contact.html
- admin_login.html
- admin_notice.html
- admin_panel.html
- manage_notices.html
- manage_students.html
- manage_teachers.html
- new_student.html
admin_base.html
{% load static %}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{% block title %}{% endblock %}</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous">
<style>
.card{
box-shadow: 15px 15px 25px 1px black;
}
</style>
</head>
<body>
<nav class="navbar navbar-dark bg-dark fixed-top">
<div class="container-fluid">
<button class="navbar-toggler" type="button" data-bs-toggle="offcanvas"
data-bs-target="#offcanvasDarkNavbar" aria-controls="offcanvasDarkNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<a class="navbar-brand" href="#">Welcome to Admin Panel</a>
<div class="offcanvas offcanvas-start text-bg-dark" tabindex="-1" id="offcanvasDarkNavbar"
aria-labelledby="offcanvasDarkNavbarLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasDarkNavbarLabel">Menu Bar</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="offcanvas"
aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<form class="d-flex mt-3" role="search">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-success" type="submit">Search</button>
</form>
<ul class="navbar-nav justify-content-start flex-grow-1 pe-3">
<li class="nav-item">
<a class="nav-link" aria-current="page" href="{% url 'admin_panel' %}">Dashboard</a>
</li>
<li class="nav-item">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown"
aria-expanded="false">
Students
</a>
<ul class="dropdown-menu dropdown-menu-dark">
<li><a class="dropdown-item" href="{% url 'add_student' %}">Add Student</a></li>
<li><a class="dropdown-item" href="{% url 'manage_students' %}">Manage students</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown"
aria-expanded="false">
Teachers
</a>
<ul class="dropdown-menu dropdown-menu-dark">
<li><a class="dropdown-item" href="{% url 'add_teacher' %}">Add Faculty</a></li>
<li><a class="dropdown-item" href="{% url 'manage_teachers' %}">Manage Teachers</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown"
aria-expanded="false">
Notices
</a>
<ul class="dropdown-menu dropdown-menu-dark">
<li><a class="dropdown-item" href="{% url 'add_notice' %}">Add Notice</a></li>
<li><a class="dropdown-item" href="{% url 'manage_notices' %}">Manage Notices</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown"
aria-expanded="false">
Pages
</a>
<ul class="dropdown-menu dropdown-menu-dark">
<li><a class="dropdown-item" href="{% url 'admin_about' %}">About</a></li>
<li><a class="dropdown-item" href="{% url 'admin_contact' %}">Contact</a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link text-danger" href="{% url 'admin_logout' %}">Logout</a>
</li>
</ul>
</div>
</div>
</div>
</nav>
<video autoplay muted loop id="myVideo" style="width: 100%">
<source src="{% static 'bg_vdo/bgVideo.mp4' %}" type="video/mp4">
</video>
{% block body %}
{% endblock %}
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4"
crossorigin="anonymous">
</script>
</body>
</html>
admin_panel.html
{% extends 'admin/admin_base.html' %}
{% block title %}
Admin - Dashboard
{% endblock %}
{% block body %}
<table class="" style="position: absolute; top: 200px; left: 50px;">
<tr>
<td>
<div class="card" style="width: 36rem; margin: 100px;">
<div class="card-body">
<h1 class="card-title text-danger">{{students.count}}</h1>
<h4 class="card-text">Students</h4>
</div>
</div>
</td>
<td>
<div class="card" style="width: 36rem;">
<div class="card-body">
<h1 class="card-title text-danger">{{teachers.count}}</h1>
<h4 class="card-text">Teachers</h4>
</div>
</div>
</td>
</tr>
</table>
{% endblock %}
admin_notice.html
{% extends 'admin/admin_base.html' %}
{% block title %}
Admin - Notices
{% endblock %}
{% block body %}
<div class="container" style="margin: 100px;">
<form action="{% url 'add_notice' %}" method="post">
{% csrf_token %}
<h2>Add Notice</h2>
<input type="text" name="notice_title" class="form-control" placeholder="Title" required>
<br>
<textarea name="notice_content" cols="30" class="form-control" rows="10" placeholder="Notice Content" required></textarea>
<br>
<div class="input-group mb-3">
<select class="form-select" name="notice_status" id="inputGroupSelect01">
<option value="True">For Public</option>
<option value="False">For Students</option>
</select>
</div>
<br>
<input type="submit" value="Add Notice" class="btn btn-primary form-control">
<br>
</form>
</div>
{% endblock %}
manage_notices.html
{% extends 'admin/admin_base.html' %}
{% block title %}
Admin - Manage Notices
{% endblock %}
{% block body %}
<div class="container" style="margin: 100px;">
<h1>Manage Notices</h1>
<table class="table table-striped">
<thead>
<tr>
<th>S.No</th>
<th>Title</th>
<th>Content</th>
<th>Is Public</th>
<th>Update</th>
</tr>
</thead>
<tbody>
{% for notice in notices %}
<tr>
<th scope="row">{{forloop.counter}}</th>
<td>{{notice.title}}</td>
<td>{{notice.content}}</td>
<td>{{notice.isPublic}}</td>
<td>
<a href="{% url 'delete_notice' notice.id %}" style="text-decoration: none;">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
class="bi bi-trash3-fill" viewBox="0 0 16 16">
<path
d="M11 1.5v1h3.5a.5.5 0 0 1 0 1h-.538l-.853 10.66A2 2 0 0 1 11.115 16h-6.23a2 2 0 0 1-1.994-1.84L2.038 3.5H1.5a.5.5 0 0 1 0-1H5v-1A1.5 1.5 0 0 1 6.5 0h3A1.5 1.5 0 0 1 11 1.5Zm-5 0v1h4v-1a.5.5 0 0 0-.5-.5h-3a.5.5 0 0 0-.5.5ZM4.5 5.029l.5 8.5a.5.5 0 1 0 .998-.06l-.5-8.5a.5.5 0 1 0-.998.06Zm6.53-.528a.5.5 0 0 0-.528.47l-.5 8.5a.5.5 0 0 0 .998.058l.5-8.5a.5.5 0 0 0-.47-.528ZM8 4.5a.5.5 0 0 0-.5.5v8.5a.5.5 0 0 0 1 0V5a.5.5 0 0 0-.5-.5Z" />
</svg>
</a>
/
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
class="bi bi-pencil-square" data-bs-toggle="modal" data-bs-target="#exampleModal{{notice.id}}" viewBox="0 0 16 16">
<path
d="M15.502 1.94a.5.5 0 0 1 0 .706L14.459 3.69l-2-2L13.502.646a.5.5 0 0 1 .707 0l1.293 1.293zm-1.75 2.456-2-2L4.939 9.21a.5.5 0 0 0-.121.196l-.805 2.414a.25.25 0 0 0 .316.316l2.414-.805a.5.5 0 0 0 .196-.12l6.813-6.814z" />
<path fill-rule="evenodd"
d="M1 13.5A1.5 1.5 0 0 0 2.5 15h11a1.5 1.5 0 0 0 1.5-1.5v-6a.5.5 0 0 0-1 0v6a.5.5 0 0 1-.5.5h-11a.5.5 0 0 1-.5-.5v-11a.5.5 0 0 1 .5-.5H9a.5.5 0 0 0 0-1H2.5A1.5 1.5 0 0 0 1 2.5v11z" />
</svg>
</td>
</tr>
<!-- Modal -->
<div class="modal fade" id="exampleModal{{notice.id}}" tabindex="-1" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Update Notice Details</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="{% url 'update_notice' notice.id %}" method="post">
{% csrf_token %}
<input type="text" name="title" value="{{notice.title}}" class="form-control" placeholder="title">
<br>
<textarea name="content" id="" cols="30" rows="10" placeholder="Content" class="form-control">{{notice.content}}</textarea>
<br>
<div class="input-group mb-3">
<label class="input-group-text" for="inputGroupSelect01">Status</label>
<select class="form-select" name="status" id="inputGroupSelect01">
<option selected>{{notice.isPublic}}</option>
<option value="True">True</option>
<option value="False">False</option>
</select>
</div>
<br><br>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<input type="submit" class="btn btn-primary" value="Update">
</div>
</form>
</div>
</div>
</div>
</div>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}
new_student.html
{% extends 'admin/admin_base.html' %}
{% block title %}
Admin - New Student
{% endblock %}
{% block body %}
<div class="container" style="margin: 80px;">
<h2>Add Student</h2>
<form action="{% url 'add_student' %}" method="post">
{% csrf_token %}
<input type="text" name="full_name" class="form-control" placeholder="Full Name">
<br>
<input type="text" name="f_name" class="form-control" placeholder="Father's Name">
<br>
<input type="text" name="m_name" class="form-control" placeholder="Mother's Name">
<br>
<div class="input-group mb-3">
<label class="input-group-text" for="inputGroupSelect01">Gender</label>
<select class="form-select" name="gender" id="inputGroupSelect01">
<option selected>Choose...</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
<br>
<input type="text" name="address" class="form-control" placeholder="Permanant Address">
<br>
<input type="text" name="city" class="form-control" placeholder="City">
<br>
<input type="email" name="stu_email" placeholder="Email" class="form-control">
<br>
<input type="tel" name="contact_number" class="form-control" placeholder="Contact Number">
<br>
<input type="date" name="dob" class="form-control" id="">
<br>
<div class="input-group mb-3">
<label class="input-group-text" for="inputGroupSelect01">Select Course</label>
<select class="form-select" name="course" id="inputGroupSelect01">
<option selected>Choose...</option>
<option value="BSC">BSC</option>
<option value="BA">BA</option>
<option value="BCOM">BCOM</option>
<option value="BBA">BBA</option>
<option value="BCA">BCA</option>
<option value="BTECH">BTECH</option>
<option value="MSC">MSC</option>
<option value="MA">MA</option>
<option value="MCOM">MCOM</option>
<option value="MBA">MBA</option>
<option value="MCA">MCA</option>
<option value="MTECH">MTECH</option>
</select>
</div>
<br>
<input type="text" name="stu_id" class="form-control" placeholder="Student Id">
<br><br>
<h4>Login Details</h4>
<hr>
<input type="text" name="stu_user_name" class="form-control" placeholder="Username">
<br>
<input type="password" name="stu_pwd" class="form-control" placeholder="Password">
<br>
<input type="submit" class="btn btn-primary form-control" value="Add Student">
</form>
</div>
{% endblock %}
manage_students.html
{% extends 'admin/admin_base.html' %}
{% block title %}
Admin - Manage Students
{% endblock %}
{% block body %}
<div class="container-fluid w-100" style="margin: 100px 0px;">
<h1>Manage Students</h1>
<hr>
<table class="table table-striped">
<thead>
<tr>
<th>Student Id</th>
<th>Full Name</th>
<th>Father Name</th>
<th>Mother Name</th>
<th>Date of Birth</th>
<th>Gender</th>
<th>Address</th>
<th>City</th>
<th>Email</th>
<th>Contact Number</th>
<th>Course</th>
<th>Update</th>
</tr>
</thead>
<tbody>
{% for student in students %}
<tr>
<td>{{student.stu_id}}</td>
<td>{{student.full_name}}</td>
<td>{{student.father_name}}</td>
<td>{{student.mother_name}}</td>
<td>{{student.date_of_birth}}</td>
<td>{{student.gender}}</td>
<td>{{student.address}}</td>
<td>{{student.city}}</td>
<td>{{student.email}}</td>
<td>{{student.contact_num}}</td>
<td>{{student.course}}</td>
<td>
<a href="{% url 'delete_student' student.id %}" style="text-decoration: none;">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
class="bi bi-trash3-fill" viewBox="0 0 16 16">
<path
d="M11 1.5v1h3.5a.5.5 0 0 1 0 1h-.538l-.853 10.66A2 2 0 0 1 11.115 16h-6.23a2 2 0 0 1-1.994-1.84L2.038 3.5H1.5a.5.5 0 0 1 0-1H5v-1A1.5 1.5 0 0 1 6.5 0h3A1.5 1.5 0 0 1 11 1.5Zm-5 0v1h4v-1a.5.5 0 0 0-.5-.5h-3a.5.5 0 0 0-.5.5ZM4.5 5.029l.5 8.5a.5.5 0 1 0 .998-.06l-.5-8.5a.5.5 0 1 0-.998.06Zm6.53-.528a.5.5 0 0 0-.528.47l-.5 8.5a.5.5 0 0 0 .998.058l.5-8.5a.5.5 0 0 0-.47-.528ZM8 4.5a.5.5 0 0 0-.5.5v8.5a.5.5 0 0 0 1 0V5a.5.5 0 0 0-.5-.5Z" />
</svg>
</a>
/
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
class="bi bi-pencil-square" data-bs-toggle="modal" data-bs-target="#exampleModal{{student.id}}" viewBox="0 0 16 16">
<path
d="M15.502 1.94a.5.5 0 0 1 0 .706L14.459 3.69l-2-2L13.502.646a.5.5 0 0 1 .707 0l1.293 1.293zm-1.75 2.456-2-2L4.939 9.21a.5.5 0 0 0-.121.196l-.805 2.414a.25.25 0 0 0 .316.316l2.414-.805a.5.5 0 0 0 .196-.12l6.813-6.814z" />
<path fill-rule="evenodd"
d="M1 13.5A1.5 1.5 0 0 0 2.5 15h11a1.5 1.5 0 0 0 1.5-1.5v-6a.5.5 0 0 0-1 0v6a.5.5 0 0 1-.5.5h-11a.5.5 0 0 1-.5-.5v-11a.5.5 0 0 1 .5-.5H9a.5.5 0 0 0 0-1H2.5A1.5 1.5 0 0 0 1 2.5v11z" />
</svg>
</td>
</tr>
<!-- Modal -->
<div class="modal fade" id="exampleModal{{student.id}}" tabindex="-1" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Update Student's Details</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="{% url 'update_student' student.id %}" method="post">
{% csrf_token %}
<input type="text" name="full_name" value="{{student.full_name}}" class="form-control" placeholder="Full Name">
<br>
<input type="text" name="f_name" value="{{student.father_name}}" class="form-control" placeholder="Father's Name">
<br>
<input type="text" name="m_name" value="{{student.mother_name}}" class="form-control" placeholder="Mother's Name">
<br>
<div class="input-group mb-3">
<label class="input-group-text" for="inputGroupSelect01">Gender</label>
<select class="form-select" name="gender" id="inputGroupSelect01">
<option selected>{{student.gender}}</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
<br>
<input type="text" name="address" value="{{student.address}}" class="form-control" placeholder="Permanant Address">
<br>
<input type="text" name="city" value="{{student.city}}" class="form-control" placeholder="City">
<br>
<input type="email" name="stu_email" value="{{student.email}}" placeholder="Email" class="form-control">
<br>
<input type="tel" name="contact_number" value="{{student.contact_num}}" class="form-control" placeholder="Contact Number">
<br>
<small>Current DoB: {{student.date_of_birth}}</small>
<input type="date" name="dob" value="{{student.date_of_birth}}" class="form-control" id="">
<br>
<div class="input-group mb-3">
<label class="input-group-text" for="inputGroupSelect01">Select Course</label>
<select class="form-select" name="course" id="inputGroupSelect01">
<option selected>{{student.course}}</option>
<option value="BSC">BSC</option>
<option value="BA">BA</option>
<option value="BCOM">BCOM</option>
<option value="BBA">BBA</option>
<option value="BCA">BCA</option>
<option value="BTECH">BTECH</option>
<option value="MSC">MSC</option>
<option value="MA">MA</option>
<option value="MCOM">MCOM</option>
<option value="MBA">MBA</option>
<option value="MCA">MCA</option>
<option value="MTECH">MTECH</option>
</select>
</div>
<br>
<input type="text" name="stu_id" value="{{student.stu_id}}" class="form-control" placeholder="Student Id">
<br><br>
<h4>Login Details</h4>
<hr>
<input type="text" value="{{student.user_name}}" name="stu_user_name" class="form-control" placeholder="Username">
<br>
<input type="password" value="{{student.password}}" name="stu_pwd" class="form-control" placeholder="Password">
<br>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<input type="submit" class="btn btn-primary" value="Update">
</div>
</form>
</div>
</div>
</div>
</div>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}
add_teacher.html
{% extends 'admin/admin_base.html' %}
{% block body %}
<div class="container" style="margin: 80px;">
<h2>Add Faculty</h2>
<form action="{% url 'add_teacher' %}" method="post">
{% csrf_token %}
<input type="text" name="full_name" class="form-control" placeholder="Full Name">
<br>
<input type="email" name="email" placeholder="Email" class="form-control">
<br>
<input type="tel" name="contact_number" class="form-control" placeholder="Contact Number">
<br>
<input type="text" placeholder="Mention Qualification with Commas" class="form-control" name="qualification">
<br>
<div class="input-group mb-3">
<label class="input-group-text" for="inputGroupSelect01">Gender</label>
<select class="form-select" name="gender" id="inputGroupSelect01" required>
<option selected>{{student.gender}}</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
<br><br>
<input type="submit" class="btn btn-primary form-control" value="Add Faculty">
</form>
</div>
{% endblock %}
manage_teachers.html
{% extends 'admin/admin_base.html' %}
{% block title %}
Admin - Manage Teachers
{% endblock %}
{% block body %}
<div class="container" style="margin: 100px;">
<h1>Manage Faculty</h1>
<table class="table table-striped">
<thead>
<tr>
<th>S.No</th>
<th>Full Name</th>
<th>Gender</th>
<th>Email</th>
<th>Contact Number</th>
<th>Qualification</th>
<th>Update</th>
</tr>
</thead>
<tbody>
{% for teacher in teachers %}
<tr>
<th scope="row">{{forloop.counter}}</th>
<td>{{teacher.full_name}}</td>
<td>{{teacher.gender}}</td>
<td>{{teacher.email}}</td>
<td>{{teacher.contact_num}}</td>
<td>{{teacher.qualification}}</td>
<td>
<a href="{% url 'delete_teacher' teacher.id %}" style="text-decoration: none;">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
class="bi bi-trash3-fill" viewBox="0 0 16 16">
<path
d="M11 1.5v1h3.5a.5.5 0 0 1 0 1h-.538l-.853 10.66A2 2 0 0 1 11.115 16h-6.23a2 2 0 0 1-1.994-1.84L2.038 3.5H1.5a.5.5 0 0 1 0-1H5v-1A1.5 1.5 0 0 1 6.5 0h3A1.5 1.5 0 0 1 11 1.5Zm-5 0v1h4v-1a.5.5 0 0 0-.5-.5h-3a.5.5 0 0 0-.5.5ZM4.5 5.029l.5 8.5a.5.5 0 1 0 .998-.06l-.5-8.5a.5.5 0 1 0-.998.06Zm6.53-.528a.5.5 0 0 0-.528.47l-.5 8.5a.5.5 0 0 0 .998.058l.5-8.5a.5.5 0 0 0-.47-.528ZM8 4.5a.5.5 0 0 0-.5.5v8.5a.5.5 0 0 0 1 0V5a.5.5 0 0 0-.5-.5Z" />
</svg>
</a>
/
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor"
class="bi bi-pencil-square" data-bs-toggle="modal" data-bs-target="#exampleModal{{teacher.id}}" viewBox="0 0 16 16">
<path
d="M15.502 1.94a.5.5 0 0 1 0 .706L14.459 3.69l-2-2L13.502.646a.5.5 0 0 1 .707 0l1.293 1.293zm-1.75 2.456-2-2L4.939 9.21a.5.5 0 0 0-.121.196l-.805 2.414a.25.25 0 0 0 .316.316l2.414-.805a.5.5 0 0 0 .196-.12l6.813-6.814z" />
<path fill-rule="evenodd"
d="M1 13.5A1.5 1.5 0 0 0 2.5 15h11a1.5 1.5 0 0 0 1.5-1.5v-6a.5.5 0 0 0-1 0v6a.5.5 0 0 1-.5.5h-11a.5.5 0 0 1-.5-.5v-11a.5.5 0 0 1 .5-.5H9a.5.5 0 0 0 0-1H2.5A1.5 1.5 0 0 0 1 2.5v11z" />
</svg>
</td>
</tr>
<!-- Modal -->
<div class="modal fade" id="exampleModal{{teacher.id}}" tabindex="-1" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Update Teacher Details</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="{% url 'update_teacher' teacher.id %}" method="post">
{% csrf_token %}
<input type="text" name="full_name" value="{{teacher.full_name}}" class="form-control" placeholder="title">
<br>
<input type="email" name="email" placeholder="Email" class="form-control" value="{{teacher.email}}">
<br>
<input type="number" name="contact_number" placeholder="Contact Number" class="form-control" value="{{teacher.contact_num}}">
<br>
<textarea name="qualification" placeholder="Qualification" class="form-control" cols="30" rows="10">{{teacher.qualification}}</textarea>
<div class="input-group mb-3">
<label class="input-group-text" for="inputGroupSelect01">Gender</label>
<select class="form-select" name="gender" id="inputGroupSelect01">
<option selected>{{teacher.gender}}</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
<br><br>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<input type="submit" class="btn btn-primary" value="Update">
</div>
</form>
</div>
</div>
</div>
</div>
{% endfor %}
</tbody>
</table>
</div>
{% endblock %}
admin_about.html
{% extends 'admin/admin_base.html' %}
{% block body %}
<div class="container" style="margin: 100px;">
<h2>Update About</h2>
<br>
<form action="{% url 'update_about' aboutDetails.first.id %}" method="post">
{% csrf_token %}
<textarea name="text" class="form-control" cols="30" rows="10">{{aboutDetails.first.about}}
</textarea>
<br>
<input type="submit" class="form-control btn btn-primary" value="Update">
</form>
</div>
{% endblock %}
admin_contact.html
{% extends 'admin/admin_base.html' %}
{% block body %}
<div class="container" style="margin: 100px;">
<h2>Update Contact</h2>
<br>
<form action="{% url 'update_contact' contactDetails.first.id %}" method="post">
{% csrf_token %}
<input type="text" name="address" value="{{contactDetails.first.address}}" placeholder="Address" class="form-control">
<br>
<input type="email" name="email" value="{{contactDetails.first.email}}" placeholder="Email" class="form-control">
<br>
<input type="number" name="contact" value="{{contactDetails.first.contact_num}}" placeholder="Contact Number" class="form-control">
<br>
<input type="submit" class="form-control btn btn-primary" value="Update">
</form>
</div>
{% endblock %}
admin_login.html
{% extends 'base.html' %}
{% block body %}
<div class="container my-5 w-50">
<h1 class="text-center">Admin Login</h1>
<form action="{% url 'admin_login' %}" method="post">
{% csrf_token %}
<input type="email" placeholder="Email" class="form-control" name="email">
<br>
<input type="password" placeholder="Password" class="form-control" name="pwd">
<br>
<input type="submit" class="btn btn-primary form-control" value="Login">
</form>
</div>
{% endblock %}
That's It. Our project is ready to run. To start our server in Django, we have to use the following command:-
python manage.py runserver
If you have any query or face any problem , then you can comment me below.
Thank You.
Top comments (11)
The model is wrong or incomplete students and teachers would never be able to log in this way. looks like code made by some AI. There is no relation to the Django user model.
Explain the problem
After rereading the code I see that you are using many bad practices, the sections to validate the user, you do not use the authentication provided by Django. this has a big security problem. When the student or admin user tries to start the section, the information will be sent without encrypting this, anyone on the network can capture that password because django forms are not used with its passwordInput widget. remember that passwords have to be encoded in the database, which is not the case with your student model. You use a lot of bad practices, the correct way to do this is with AbstractUser or AbstractBaseUser, use a login form with a passwordInput widget (the information is sent encrypted) and use a CustomUserManager that when creating the user calls user.set_password( password) in this way the password is encoded in the database, you comply with European regulations and protect the personal information of users.
So I have to use-
Authentication and Autherization
AbstractUser or AbstractBaseUser
Yes, that would be the correct way. You can also add a OneToOneField to the student and teacher model, that way you can keep the models you already have. I will leave you the best tutorial that explains this whole topic very well: simpleisbetterthancomplex.com/tuto...
did you finished the "college management system" project ?
can you share the code with me ?
i also want to learn and build "college management system" type projects
did you finished the "college management system" project ?
can you share the code with me ?
i also want to learn and build "college management system" type projects
How can admin login ?
I'm trying to log in with the email and password I created
python manage.py createsuperuser
which does not happen, the page is not updated
authorization by the administrator does not occur
there is no transition to the page 127.0.0.1:8000/admin_panel/dashboard
Here is adminLogin function views.py file. You have to use admin@gmail.com for the email and admin@123 for the password.
some problem in this code ....please help
what problem? Explain me.