[python毕业设计]免费分享一套基于Python的Django学生选课系统【论文+源码+SQL脚本】,帅呆了~~

CSDN 2024-10-13 10:05:02 阅读 93

大家好,我是java1234_小锋老师,看到一个不错的基于Python的Django学生选课系统,分享下哈。

项目视频演示

【免费】基于Python的Django学生选课系统 Python毕业设计_哔哩哔哩_bilibili

项目介绍

随着信息技术的快速发展,学生选课系统逐渐成为高等教育中不可或缺的一部分。本文介绍了一种基于Python语言开发的学生选课系统,旨在为学生提供方便、快捷的选课体验,同时为教师和管理员提供高效的课程管理工具。系统采用MVC(模型-视图-控制器)架构,确保了系统的可维护性和扩展性。

    系统功能包括学生注册与登录、课程浏览、选课与退课、成绩查询以及管理员对课程的管理。通过Django 框架构建后端,利用Mysql数据库存储用户信息和课程数据,前端则采用HTML、CSS和JavaScript技术实现动态交互。本文详细阐述了系统的设计思路、数据库结构及主要功能模块的实现。

    经过测试,该系统能够有效处理学生的选课需求,减轻了人工管理的压力,提高了选课的效率与准确性。同时,系统界面友好,操作简单,能够满足不同用户的需求。最后,本文讨论了系统在实际应用中的优势和未来的改进方向,包括数据分析功能的引入和移动端的适配。要想实现学生选课系统的各项功能,需要后台数据库的大力支持。管理员验证注册信息,收集的用户信息,并由此分析得出的关联信息等大量的数据都由数据库管理。本文中数据库服务器端采用了Mysql作为后台数据库,使Django Web与数据库紧密联系起来。在设计过程中,充分保证了系统代码的良好可读性、实用性、易扩展性、通用性、便于后期维护、操作方便以及页面简洁等特点。

本系统的开发使获取学生选课系统信息能够更加方便快捷,同时也使学生选课系统信息变的更加系统化、有序化。系统界面较友好,易于操作。

系统展示

部分代码

<code><!DOCTYPE html>

<html lang="zh">code>

{% load static %}

<head>

<meta charset="UTF-8">code>

<meta name="viewport" content="width=device-width, initial-scale=1.0">code>

<meta http-equiv="X-UA-Compatible" content="ie=edge">code>

<title>登录页面</title>

<link rel="stylesheet" type="text/css" href="{% static 'libs/models/models.css' %}"/>code>

<link rel="stylesheet" type="text/css" href="{% static 'css/comm.css' %}"/>code>

<link rel="stylesheet" type="text/css" href="{% static 'css/login.css' %}"/>code>

</head>

<body>

<div class="login-container">code>

<div class="login-body">code>

<div class="login-title">code>

学生选课系统

</div>

<div class="login-form">code>

<form name="loginForm" action="" class="fater-form">code>

<div class="fater-form-block">code>

<input type="text" name="userName" placeholder="请输入登录账号"/>code>

</div>

<div class="fater-form-block">code>

<input type="password" name="passWord" placeholder="请输入登录密码"/>code>

</div>

<div class="fater-form-block">code>

<button type="button" id="loginFormBtn" class="fater-btn fater-btn-primary fater-btn-block">code>

登录

</button>

</div>

</form>

</div>

</div>

</div>

{% include 'templates/commjs.html' %}

<script src="{% static 'js/login.js' %}" type="text/javascript" charset="utf-8"></script>code>

</body>

</html>

import json

import time

from django.core import serializers

from django.core.paginator import Paginator

from django.db.models import Q

from django.http import HttpResponse, JsonResponse, HttpResponseRedirect

from django.shortcuts import render

from app import models

'''

检查指定的参数是否存在

存在返回 True

不存在返回 False

'''

def isExit(param):

if (param == None) or (param == ''):

return False

else:

return True

'''

转换分页查询信息

'''

def parasePage(pageIndex, pageSize, pageTotal, count, data):

return {'pageIndex': pageIndex, 'pageSize': pageSize, 'pageTotal': pageTotal, 'count': count, 'data': data}

'''

成功响应信息

'''

def success(msg = '处理成功'):

resl = {'code': 0, 'msg': msg}

return HttpResponse(json.dumps(resl), content_type='application/json; charset=utf-8')code>

'''

成功响应信息, 携带数据

'''

def successData(data, msg = '处理成功'):

resl = {'code': 0, 'msg': msg, 'data': data}

return HttpResponse(json.dumps(resl), content_type='application/json; charset=utf-8')code>

'''

系统警告信息

'''

def warn(msg = '操作异常,请重试'):

resl = {'code': 1, 'msg': msg}

return HttpResponse(json.dumps(resl), content_type='application/json; charset=utf-8')code>

'''

系统异常信息

'''

def error(msg = '系统异常'):

resl = {'code': 2, 'msg': '系统异常'}

return HttpResponse(json.loads(resl), content_type='application/json; charset=utf-8')code>

def sys_index_view(request):

return render(request, "Index.html")

def sys_login_view(request):

return render(request, "login.html")

def sys_login_data(request):

userName = request.POST.get('userName')

passWord = request.POST.get('passWord')

user = models.Users.objects.filter(userName=userName)

if(user.exists()):

user = user.first()

if user.passWord == passWord:

login_user = {

'id': user.id,

'userName': user.userName,

'passWord': user.passWord,

'name': user.name,

'age': user.age,

'gender': user.gender,

'type': user.type,

}

request.session["user"] = login_user

return success()

else:

return warn('用户密码输入错误')

else:

return warn('用户名输入错误')

def sys_logout_view(request):

del request.session["user"]

return HttpResponseRedirect('/projects/login')

def sys_info_data(request):

user = request.session.get('user')

data = models.Users.objects.filter(id = user['id'])

resl = {}

for item in data:

resl = {

'id': item.id,

'userName': item.userName,

'passWord': item.passWord,

'name': item.name,

'age': item.age,

'gender': item.gender,

'type': item.type,

}

return successData(resl)

def sys_info_form_data(request):

user = request.session.get('user')

models.Users.objects.filter(id = user['id']).update(

userName=request.POST.get('userName'),

name=request.POST.get('name'),

age=request.POST.get('age'),

gender=request.POST.get('gender'),

)

data = models.Users.objects.filter(id=user['id'])

resl = {}

for item in data:

resl = {

'id': item.id,

'userName': item.userName,

'passWord': item.passWord,

'name': item.name,

'age': item.age,

'gender': item.gender,

'type': item.type,

}

del request.session["user"]

request.session["user"] = resl

return successData(user)

def sys_pwd_form_data(request):

user = request.session.get('user')

models.Users.objects.filter(id=user['id']).update(

passWord=request.POST.get('password'),

)

data = models.Users.objects.filter(id=user['id'])

resl = {}

for item in data:

resl = {

'id': item.id,

'userName': item.userName,

'passWord': item.passWord,

'name': item.name,

'age': item.age,

'gender': item.gender,

'type': item.type,

}

del request.session["user"]

request.session["user"] = resl

return successData(user)

def college_view(request):

return render(request, "Colleges.html")

def college_data_page(request):

pageIndex = request.GET.get('pageIndex', 1)

pageSize = request.GET.get('pageSize', 10)

name = request.GET.get('name')

if isExit(name):

data = models.Colleges.objects.all().filter(name__contains=name).order_by("-createTime")

else:

data = models.Colleges.objects.all().order_by("-createTime")

paginator = Paginator(data, pageSize)

resl = []

for item in list(paginator.page(pageIndex)):

temp = {

'id': item.id,

'name': item.name,

'createTime': item.createTime

}

resl.append(temp)

temp = parasePage(pageIndex, pageSize,

paginator.page(pageIndex).paginator.num_pages, paginator.count, resl)

return successData(temp)

def college_data_info(request):

id = request.GET.get('id')

data = models.Colleges.objects.filter(id=id)

resl = {}

for item in data:

resl = {

'id': item.id,

'name': item.name,

'createTime': item.createTime

}

return successData(resl)

def college_data_add(request):

models.Colleges.objects.create(id = int(time.time()),

name = request.POST.get('name'),

createTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

)

return success()

def college_data_upd(request):

models.Colleges.objects.filter(id = request.POST.get('id')).update(name=request.POST.get('name'))

return success()

def college_data_del(request):

if models.Students.objects.filter(college__id=request.POST.get('id')).exists():

return warn('学院学生未结业,无法删除')

else:

models.Colleges.objects.filter(id=request.POST.get('id')).delete()

return success()

def major_view(request):

return render(request, "Majors.html")

def major_data_page(request):

pageIndex = request.GET.get('pageIndex', 1)

pageSize = request.GET.get('pageSize', 10)

name = request.GET.get('name')

if isExit(name):

data = models.Majors.objects.all().filter(name__contains=name).order_by("-createTime")

else:

data = models.Majors.objects.all().order_by("-createTime")

paginator = Paginator(data, pageSize)

resl = []

for item in list(paginator.page(pageIndex)):

temp = {

'id': item.id,

'name': item.name,

'createTime': item.createTime

}

resl.append(temp)

temp = parasePage(pageIndex, pageSize,

paginator.page(pageIndex).paginator.num_pages, paginator.count, resl)

return successData(temp)

def major_data_info(request):

id = request.GET.get('id')

data = models.Majors.objects.filter(id=id)

resl = {}

for item in data:

resl = {

'id': item.id,

'name': item.name,

'createTime': item.createTime

}

return successData(resl)

def major_data_add(request):

models.Majors.objects.create(id = int(time.time()),

name = request.POST.get('name'),

createTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

)

return success()

def major_data_upd(request):

models.Majors.objects.filter(id = request.POST.get('id')).update(name=request.POST.get('name'))

return success()

def major_data_del(request):

if models.Students.objects.filter(major__id=request.POST.get('id')).exists():

return warn('学生未结业,无法删除')

else:

models.Majors.objects.filter(id=request.POST.get('id')).delete()

return success()

def project_view(request):

return render(request, "Projects.html")

def project_data_page(request):

pageIndex = request.GET.get('pageIndex', 1)

pageSize = request.GET.get('pageSize', 10)

name = request.GET.get('name')

if isExit(name):

data = models.Projects.objects.all().filter(name__contains=name).order_by("-createTime")

else:

data = models.Projects.objects.all().order_by("-createTime")

paginator = Paginator(data, pageSize)

resl = []

for item in list(paginator.page(pageIndex)):

temp = {

'id': item.id,

'name': item.name,

'createTime': item.createTime

}

resl.append(temp)

temp = parasePage(pageIndex, pageSize,

paginator.page(pageIndex).paginator.num_pages, paginator.count, resl)

return successData(temp)

def project_data_info(request):

id = request.GET.get('id')

data = models.Projects.objects.filter(id=id)

resl = {}

for item in data:

resl = {

'id': item.id,

'name': item.name,

'createTime': item.createTime

}

return successData(resl)

def project_data_grade(request):

select_projects = []

select_project_data = models.WorkPalns.objects.filter(grade__id = request.POST.get('id')).values_list('project_id')

for item in select_project_data:

select_projects.append(item)

projects = models.Projects.objects.exclude(id__in = select_projects)

resl = []

for item in projects:

temp = {

'id': item.id,

'name': item.name

}

resl.append(temp)

return successData(resl)

def project_data_add(request):

models.Projects.objects.create(id = int(time.time()),

name = request.POST.get('name'),

createTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

)

return success()

def project_data_upd(request):

models.Projects.objects.filter(id = request.POST.get('id')).update(name=request.POST.get('name'))

return success()

def project_data_del(request):

models.Projects.objects.filter(id=request.POST.get('id')).delete()

return success()

def grade_view(request):

return render(request, "Grades.html")

def grade_data_page(request):

pageIndex = request.GET.get('pageIndex', 1)

pageSize = request.GET.get('pageSize', 10)

name = request.GET.get('name')

if isExit(name):

data = models.Grades.objects.all().filter(name__contains=name).order_by("-createTime")

else:

data = models.Grades.objects.all().order_by("-createTime")

paginator = Paginator(data, pageSize)

resl = []

for item in list(paginator.page(pageIndex)):

temp = {

'id': item.id,

'name': item.name,

'createTime': item.createTime

}

resl.append(temp)

temp = parasePage(pageIndex, pageSize,

paginator.page(pageIndex).paginator.num_pages, paginator.count, resl)

return successData(temp)

def grade_data_info(request):

id = request.GET.get('id')

data = models.Grades.objects.filter(id=id)

resl = {}

for item in data:

resl = {

'id': item.id,

'name': item.name,

'createTime': item.createTime

}

return successData(resl)

def grade_data_add(request):

models.Grades.objects.create(id = int(time.time()),

name = request.POST.get('name'),

createTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

)

return success()

def grade_data_upd(request):

models.Grades.objects.filter(id = request.POST.get('id')).update(name=request.POST.get('name'))

return success()

def grade_data_del(request):

if models.Students.objects.filter(grade__id=request.POST.get('id')).exists():

return warn('学生未结业,无法删除')

else:

models.Grades.objects.filter(id=request.POST.get('id')).delete()

return success()

def students_view(request):

colleges = models.Colleges.objects.all().values()

majors = models.Majors.objects.all().values()

grades = models.Grades.objects.all().values()

return render(request, "Students.html", {'colleges': list(colleges), 'majors': list(majors), 'grades': list(grades)})

def students_data_page(request):

pageIndex = request.GET.get('pageIndex', 1)

pageSize = request.GET.get('pageSize', 10)

studentName = request.GET.get('studentName')

majorId = request.GET.get('majorId')

collegeId = request.GET.get('collegeId')

gradeId = request.GET.get('gradeId')

qruery = Q();

if isExit(studentName):

qruery = qruery & Q(user__name__contains = studentName)

if isExit(collegeId):

qruery = qruery & Q(college__id = collegeId)

if isExit(majorId):

qruery = qruery & Q(major__id = majorId)

if isExit(gradeId):

qruery = qruery & Q(grade__id = gradeId)

data = models.Students.objects.filter(qruery)

paginator = Paginator(data, pageSize)

resl = []

for item in list(paginator.page(pageIndex)):

temp = {

'id': item.user.id,

'name': item.user.name,

'age': item.user.age,

'gender': item.user.gender,

'majorId': item.major.id,

'majorName': item.major.name,

'collegeId': item.college.id,

'collegeName': item.college.name,

'gradeId': item.grade.id,

'gradeName': item.grade.name,

}

resl.append(temp)

temp = parasePage(pageIndex, pageSize,

paginator.page(pageIndex).paginator.num_pages, paginator.count, resl)

return successData(temp)

def students_data_info(request):

id = request.GET.get('id')

data = models.Students.objects.filter(user__id=id)

resl = {}

for item in data:

resl = {

'id': item.user.id,

'majorId': item.major.id,

'collegeId': item.college.id,

'gradeId': item.grade.id,

}

return successData(resl)

def students_data_add(request):

id = int(time.time())

user = models.Users.objects.create(id = id,

userName=request.POST.get('userName'), passWord = request.POST.get('passWord'),

name=request.POST.get('name'), age = request.POST.get('age'),

gender=request.POST.get('gender'), type=request.POST.get('type'),

)

models.Students.objects.create(user = user,

major = models.Majors.objects.get(id=request.POST.get('majorId')),

college = models.Colleges.objects.get(id=request.POST.get('collegeId')),

grade = models.Grades.objects.get(id=request.POST.get('gradeId')),

)

return success()

def students_data_upd(request):

models.Students.objects.filter(user__id = request.POST.get('id')).update(

major=models.Majors.objects.get(id=request.POST.get('majorId')),

college=models.Colleges.objects.get(id=request.POST.get('collegeId')),

grade=models.Grades.objects.get(id=request.POST.get('gradeId')),

)

return success()

def students_data_del(request):

models.Students.objects.filter(user__id = request.POST.get('id')).delete()

models.Users.objects.filter(id=request.POST.get('id')).delete()

return success()

def teachers_view(request):

return render(request, "Teachers.html", {'reocrds': ['专科', '本科', '研究生', '其他']})

def teachers_data_page(request):

pageIndex = request.GET.get('pageIndex', 1)

pageSize = request.GET.get('pageSize', 10)

teacherName = request.GET.get('teacherName')

record = request.GET.get('record')

phone = request.GET.get('phone')

qruery = Q();

if isExit(teacherName):

qruery = qruery & Q(user__name__contains = teacherName)

if isExit(record):

qruery = qruery & Q(record = record)

if isExit(phone):

qruery = qruery & Q(phone = phone)

data = models.Teachers.objects.filter(qruery)

paginator = Paginator(data, pageSize)

resl = []

for item in list(paginator.page(pageIndex)):

temp = {

'id': item.user.id,

'name': item.user.name,

'age': item.user.age,

'gender': item.user.gender,

'record': item.record,

'phone': item.phone,

'address': item.address,

}

resl.append(temp)

temp = parasePage(pageIndex, pageSize,

paginator.page(pageIndex).paginator.num_pages, paginator.count, resl)

return successData(temp)

def teachers_data_info(request):

id = request.GET.get('id')

data = models.Teachers.objects.filter(user__id=id)

resl = {}

for item in data:

resl = {

'id': item.user.id,

'record': item.record,

'phone': item.phone,

'address': item.address,

}

return successData(resl)

def teachers_data_add(request):

user = models.Users.objects.create(id = int(time.time()),

userName=request.POST.get('userName'), passWord = request.POST.get('passWord'),

name=request.POST.get('name'), age = request.POST.get('age'),

gender=request.POST.get('gender'), type=request.POST.get('type')

)

models.Teachers.objects.create(user = user, address = request.POST.get('address'),

record=request.POST.get('record'), phone = request.POST.get('phone')

)

return success()

def teachers_data_upd(request):

models.Teachers.objects.filter(user__id = request.POST.get('id')).update(

address=request.POST.get('address'),

record=request.POST.get('record'),

phone=request.POST.get('phone')

)

return success()

def teachers_data_del(request):

models.Teachers.objects.filter(user__id = request.POST.get('id')).delete()

models.Users.objects.filter(id=request.POST.get('id')).delete()

return success()

def work_view(request):

return render(request, "TeacherWorks.html")

def work_data_list(request):

user = request.session.get('user')

workPlans = models.WorkPalns.objects.filter(teacher__user__id = user['id'])

resl = []

for item in workPlans:

temp = {

'id': item.id,

'projectName': item.project.name,

'gradeName': item.grade.name,

}

resl.append(temp)

return successData(resl)

def work_data_add(request):

models.WorkPalns.objects.create(id=int(time.time()),

teacher=models.Teachers.objects.get(user__id=request.POST.get('teacherId')),

grade=models.Grades.objects.get(id=request.POST.get('gradeId')),

project=models.Projects.objects.get(id=request.POST.get('projectId')),

)

return success()

def select_view(request):

user = request.session.get('user')

if user['type'] == 0:

grades = models.Grades.objects.all().values()

projects = models.Projects.objects.all().values()

return render(request, "SelectLogs.html", {'grades': grades, 'projects': projects})

elif user['type'] == 1:

grades = models.Grades.objects.all().values()

return render(request, "StudentLogs.html", {'grades': grades})

elif user['type'] == 2:

return render(request, "ProjectLogs.html")

def select_data_page(request):

pageIndex = request.GET.get('pageIndex', 1)

pageSize = request.GET.get('pageSize', 10)

teacherName = request.GET.get('teacherName')

studentName = request.GET.get('studentName')

gradeId = request.GET.get('gradeId')

projectId = request.GET.get('projectId')

qruery = Q(student__isnull = False);

if isExit(teacherName):

qruery = qruery & Q(workPaln__teacher__user__name__contains=teacherName)

if isExit(studentName):

qruery = qruery & Q(student__user__name__contains=studentName)

if isExit(gradeId):

qruery = qruery & Q(workPaln__grade__id__contains=gradeId)

if isExit(projectId):

qruery = qruery & Q(workPaln__project__id__contains=projectId)

data = models.SelectLogs.objects.filter(qruery)

paginator = Paginator(data, pageSize)

resl = []

for item in list(paginator.page(pageIndex)):

temp = {

'id': item.id,

'projectName': item.workPaln.project.name,

'gradeName': item.workPaln.grade.name,

'teacherId': item.workPaln.teacher.user.id,

'teacherName': item.workPaln.teacher.user.name,

'studentId': item.student.user.id,

'studentName': item.student.user.name,

}

resl.append(temp)

temp = parasePage(pageIndex, pageSize,

paginator.page(pageIndex).paginator.num_pages, paginator.count, resl)

return successData(temp)

def selec_data_student_select(request):

user = request.session.get('user')

student = models.Students.objects.filter(user__id = user['id']).first()

workPlans = models.WorkPalns.objects.filter(grade__id = student.grade.id)

resl = []

for item in workPlans:

isSelected = models.SelectLogs.objects.filter(student__user__id = user['id'] , workPaln__id = item.id).count() > 0

temp = {

'id': item.id,

'projectName': item.project.name,

'teacherName': item.teacher.user.name,

'teacherGender': item.teacher.user.gender,

'teacherRecord': item.teacher.record,

'isSelected': isSelected

}

resl.append(temp)

return successData(resl)

def selec_view_student_selected(request):

return render(request, "StudentProjects.html")

def select_data_teastudent_page(request):

user = request.session.get('user')

pageIndex = request.GET.get('pageIndex', 1)

pageSize = request.GET.get('pageSize', 10)

studentName = request.GET.get('studentName')

gradeId = request.GET.get('gradeId')

projectId = request.GET.get('projectId')

qruery = Q(workPaln__teacher__user__id = user['id']) & Q(student__isnull = False);

if isExit(studentName):

qruery = qruery & Q(student__user__name__contains=studentName)

if isExit(gradeId):

qruery = qruery & Q(workPaln__grade__id__contains=gradeId)

if isExit(projectId):

qruery = qruery & Q(workPaln__project__id__contains=projectId)

data = models.SelectLogs.objects.filter(qruery)

paginator = Paginator(data, pageSize)

resl = []

for item in list(paginator.page(pageIndex)):

print(item)

temp = {

'id': item.id,

'projectName': item.workPaln.project.name,

'gradeName': item.workPaln.grade.name,

'studentName': item.student.user.name,

'studenGender': item.student.user.gender,

'studenColleges': item.student.college.name,

'studenMajors': item.student.major.name,

}

resl.append(temp)

temp = parasePage(pageIndex, pageSize,

paginator.page(pageIndex).paginator.num_pages, paginator.count, resl)

return successData(temp)

def selec_data_student_selected(request):

user = request.session.get('user')

selectLogs = models.SelectLogs.objects.filter(student__user_id = user['id'])

resl = []

for item in selectLogs:

temp = {

'id': item.id,

'projectName': item.workPaln.project.name,

'teacherName': item.workPaln.teacher.user.name,

'teacherGender': item.workPaln.teacher.user.gender,

'teacherRecord': item.workPaln.teacher.record,

}

resl.append(temp)

return successData(resl)

def selec_view_student_selected(request):

return render(request, "StudentProjects.html")

def select_data_add(request):

user = request.session.get('user')

models.SelectLogs.objects.create(id = int(time.time()),

student=models.Students.objects.get(user__id=user['id']),

workPaln=models.WorkPalns.objects.get(id=request.POST.get('planId')),

)

return success()

源码代码

链接:https://pan.baidu.com/s/1NBj-BRxyR8-4kfEriDq3Ww 

提取码:1234



声明

本文内容仅代表作者观点,或转载于其他网站,本站不以此文作为商业用途
如有涉及侵权,请联系本站进行删除
转载本站原创文章,请注明来源及作者。