【Python源码】基于Flask的学生管理系统-源码

基于Flask的学生管理系统2023年最新毕业设计

    • 一、项目简介
    • 二、项目技术
    • 三、项目功能
    • 四、运行截图
    • 五、部分代码

二、项目技术

Flask后端框架、python、mysql数据库、BootStrap前端框架。

三、项目功能

四、运行截图

系统首页:

【Python源码】基于Flask的学生管理系统-源码_第1张图片

【Python源码】基于Flask的学生管理系统-源码_第2张图片

【Python源码】基于Flask的学生管理系统-源码_第3张图片

【Python源码】基于Flask的学生管理系统-源码_第4张图片

五、部分代码

 1.数据库配置

# @Author : 东方天琴
# @微信
# @QQ 35771398

app = Flask(__name__,static_folder='')
app.config['DEBUG']=True
#配置session key
app.config['SECRET_KEY'] = '2cf0fa7e-48d9-11e6-93fb-c03fd53413ef'

#SQLAlchemy相关配置
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:root@localhost:3306/student'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_ECHO'] = False

 2.数据表配置

#**********数据库配置**********

#学生表
class TStudent(db.Model):
    __tablename__ = 't_student'
    id = db.Column(db.Integer, primary_key=True)
    student_no = db.Column(db.String(20))
    student_name = db.Column(db.String(100))
    department_no = db.Column(db.String(20))

#课程表
class TCourse(db.Model):
    __tablename__ = 't_course'
    id = db.Column(db.Integer, primary_key=True)
    course_no = db.Column(db.String(20))
    course_name = db.Column(db.String(100))

#成绩表
class TGrade(db.Model):
    __tablename__ = 't_grade'
    id = db.Column(db.Integer, primary_key=True)
    student_no = db.Column(db.String(20))
    course_no = db.Column(db.String(20))
    grade = db.Column(db.String(10))

#用户表
class TUser(db.Model):
    __tablename__ = 't_user'
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(20))
    password = db.Column(db.String(20))
    realname = db.Column(db.String(20))

#学院表
class TDepartment(db.Model):
    __tablename__ = 't_department'
    id = db.Column(db.Integer, primary_key=True)
    department_no = db.Column(db.String(20))
    department_name = db.Column(db.String(20))

 3.首页代码

#首页
@app.route('/')
@app.route('/index')
def index():
    
    if(checkSignIn()==False):
        return redirect('/signin')

    studentCount = db.session.query(TStudent).count()
    courseCount = db.session.query(TCourse).count()
    userCount = db.session.query(TUser).count()
    gradeCount = db.session.query(TGrade).count()

    data['studentCount']= studentCount
    data['courseCount']= courseCount
    data['userCount']= studentCount
    data['gradeCount']= gradeCount

    studentData = db.session.query(TStudent,TDepartment).outerjoin(TDepartment, TStudent.department_no==TDepartment.department_no).order_by(TStudent.id.desc()).limit(10).all()
    print(studentData)
    data['studentData']=studentData

    userData = db.session.query(TUser).order_by(TUser.id.desc()).limit(10).all()
    data['userData']=userData
   

    return render_template('index.html', **data)

 4.学生信息列表

#学生信息部分开始************************************

#查看列表带分页
@app.route('/students/',methods=['GET','POST'])
def students():

    studentNo = request.form.get('studentNo') if request.form.get('studentNo') is not None else ''
    studentName = request.form.get('studentName') if request.form.get('studentName') is not None else ''
    data['studentNo']=studentNo
    data['studentName']=studentName
    
    page = int(request.form.get('search_page')) if request.form.get('search_page') is not None and request.form.get('search_page') != '0' else 1

    query = db.session.query(TStudent).filter(or_(TStudent.student_no == studentNo, studentNo == ''),
    or_(TStudent.student_name.like('%{0}%'.format(studentName)),studentName == '')
    )
    queryPaginate = QueryPaginate(query,10,page)

    data['currdata']=queryPaginate.items
    data['pagelist']=queryPaginate.iter_pages()
    data['pages']=queryPaginate.pages
    data['page']=queryPaginate.page
    data['per_page']=queryPaginate.per_page
    data['prev_num']=queryPaginate.prev_num
    data['next_num']=queryPaginate.next_num
    
    return render_template('students.html',**data)

你可能感兴趣的:(python,flask,开发语言,pycharm,mysql)