您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“Django圖書管理系統(tǒng)怎么實現(xiàn)”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學習“Django圖書管理系統(tǒng)怎么實現(xiàn)”吧!
項目使用python開發(fā),采用Django框架,數(shù)據(jù)庫采用MySQL,根據(jù)用戶人員的不同分成兩套系統(tǒng),分別是學生系統(tǒng)和管理員系統(tǒng),功能模塊具體分成四個,分別是用戶管理模塊、圖書管理模塊、數(shù)據(jù)管理模塊、前端模塊。
用戶管理模塊實現(xiàn)的功能包括用戶注冊(分為學生注冊和管理員注冊)、用戶信息修改、用戶登錄和判定
用戶注冊和登錄
views.py中用戶注冊及登陸判定代碼段
def login(request):#登錄 return render(request, 'login.html') def student_register(request): # 學生注冊 name = request.POST.get("student_name") # 獲取學生輸入的姓名 id = request.POST.get("student_id") # 獲取學生輸入的學號 major = request.POST.get("student_major") # 獲取學生輸入的學院 email = request.POST.get("student_email") # 獲取學生輸入的郵箱 telephone = request.POST.get("student_telephone") password = request.POST.get("student_password") result1 = User.objects.filter(account=telephone) # 在用戶表中搜索該用戶名的記錄 result2 = Student.objects.filter(student_id=id) # 在學生表中搜索該學號的記錄 context = {} if len(result1) == 1: # 判斷該賬戶是否存在(即判斷是否注冊過),如果后臺存在記錄,則返回相應(yīng)的提示語句 context["info"] = "該賬戶已注冊!??!" context["status"] = 0 #零表示注冊失敗 return render(request, 'login.html', context=context) else: #該賬戶是新用戶 if len(result2) == 1:#判斷該學號是否有學生已使用 context["info"] = "該學號已占用?。?!" context["status"] = 4 return render(request, 'login.html', context=context) else: User.objects.create(account=telephone, user_password=password,user_identity='學生')#用create為user表添加一條記錄 Student.objects.create(student_name=name,student_id=id,student_major=major,student_tel=telephone,student_email=email)#用create為student表添加一條記錄 context["info"] = "注冊成功!" context["status"] = 1 #1表示注冊成功 return render(request, 'login.html', context=context) def manager_register(request): # 管理員注冊 name = request.POST.get("manager_name") # 獲取管理員輸入的姓名 id = request.POST.get("manager_id") # 獲取管理員輸入的工號 stack = request.POST.get("manager_stack") # 獲取管理員輸入的書庫 email = request.POST.get("manager_email") # 獲取管理員輸入的郵箱 telephone = request.POST.get("manager_telephone") password = request.POST.get("manager_password") result1 = User.objects.filter(account=telephone) # 在用戶表中搜索該用戶名的記錄 result2 = Manager.objects.filter(manager_id=id) # 在管理員表中搜索該工號的使用記錄 context = {} if len(result1) == 1: # 判斷該賬戶是否存在(即判斷是否注冊過),如果后臺存在記錄,則返回相應(yīng)的提示語句 context["info"] = "該賬戶已注冊?。。?quot; context["status"] = 0 #零表示注冊失敗 return render(request, 'login.html', context=context) else: #該賬戶是新用戶 if len(result2) == 1:#判斷該工號號是否有管理員已使用 context["info"] = "該工號已占用?。?!" context["status"] = 5 return render(request, 'login.html', context=context) else: User.objects.create(account=telephone, user_password=password,user_identity='管理員')#用create為user表添加一條記錄 Manager.objects.create(manager_name=name, manager_id=id, manager_stack=stack, manager_tel=telephone,manager_email=email)#用create為manager表添加一條記錄 context["info"] = "注冊成功!" context["status"] = 1 #1表示注冊成功 return render(request, 'login.html', context=context) def login_judge(request):#登入判定 global account ,global_sname,global_mname #定義全局變量account,存儲該用戶的賬戶,global_sname保存一下該學生的姓名,global_mname保存一下該學生的姓名 account = request.POST.get("telephone")#獲取前端輸入的賬戶(手機號) user_password = request.POST.get("password") result1 = User.objects.filter(account=account)#在user表里檢索是否存在該賬戶 if len(result1) == 1: # 判斷后臺是否存在該用戶,有則進一步判斷密碼是否正確 password = result1[0].user_password # 獲取后臺的密碼 identity = result1[0].user_identity # 獲取該賬戶的身份信息 if user_password == password: # 將用戶輸入的密碼和后臺密碼進行比對,如何正確,判斷該賬戶身份 if identity == '學生': result2 = Student.objects.filter(student_tel=account) global_sname = result2[0].student_name # 用全局變量保存一下該學生的姓名 context={ "name":result2[0].student_name, "id":result2[0].student_id, "major":result2[0].student_major, "telephone":result2[0].student_tel, "email":result2[0].student_email, } return render(request, 'student/student_information.html',context) # 跳轉(zhuǎn)到學生主頁界面 else: result = Manager.objects.filter(manager_tel=account) # account為全局變量 global_mname = result[0].manager_name # 用全局變量保存一下該管理員的姓名 context = { "name": result[0].manager_name, "id": result[0].manager_id, "stack": result[0].manager_stack, "telephone": result[0].manager_tel, "email": result[0].manager_email, } return render(request, 'manager/manager_information.html',context) # 跳轉(zhuǎn)到管理員主頁界面 else: # 如果不一致則返回相應(yīng)提示語句 context = { "info": "密碼錯誤?。?!", "status": 2 } return render(request, 'login.html', context=context) # 密碼錯誤回到登入界面 else: # 如果不存在該用戶則返回相應(yīng)的提示語句 context = { "info": "該賬戶不存在?。?!", "status": 3 } return render(request, 'login.html', context=context) # 賬戶不存在則繼續(xù)回到登入界面
用戶信息管理
views.py中用戶信息管理代碼段
def student_information(request):#個人信息 if request.method == "GET": #此部分是當每次點擊側(cè)邊導航欄的“個人信息”選項時,都重新顯示該用戶的個人資料 result = Student.objects.filter(student_tel=account) #account為全局變量 context = { "name": result[0].student_name, "id": result[0].student_id, "major": result[0].student_major, "telephone": result[0].student_tel, "email": result[0].student_email, } return render(request, 'student/student_information.html', context)#將該用戶的個人信息再次傳到前端頁面 else: #在student_information.html頁面的第44行中通過post方式的“保存”按鈕跳轉(zhuǎn)到此處,即完成更新數(shù)據(jù)操作(保存) email = request.POST.get("email") # 獲取郵箱 Student.objects.filter(student_tel=account).update(student_email=email)#更新數(shù)據(jù) result = Student.objects.filter(student_tel=account) # account為全局變量 此處再次傳值到前端 context = { "name": result[0].student_name, "id": result[0].student_id, "major": result[0].student_major, "telephone": result[0].student_tel, "email": result[0].student_email, } return render(request, 'student/student_information.html', context) # 將該用戶的個人信息再次傳到前端頁面 def manager_information(request):#個人信息 if request.method == "GET": #此部分是當每次點擊側(cè)邊導航欄的“個人信息”選項時,都重新顯示該管理員的個人資料 result = Manager.objects.filter(manager_tel=account) #account為全局變量 context = { "name": result[0].manager_name, "id": result[0].manager_id, "stack": result[0].manager_stack, "telephone": result[0].manager_tel, "email": result[0].manager_email, } return render(request, 'manager/manager_information.html', context)#將該用戶的個人信息再次傳到前端頁面 else: #在manager_information.html頁面的第44行中通過post方式的“保存”按鈕跳轉(zhuǎn)到此處,即完成更新數(shù)據(jù)操作(保存) stack = request.POST.get("stack") # 獲取書庫信息 email = request.POST.get("email") # 獲取郵箱 Manager.objects.filter(manager_tel=account).update(manager_email=email,manager_stack=stack)#更新數(shù)據(jù) result = Manager.objects.filter(manager_tel=account) # account為全局變量 此處再次傳值到前端 context = { "name": result[0].manager_name, "id": result[0].manager_id, "stack": result[0].manager_stack, "telephone": result[0].manager_tel, "email": result[0].manager_email, } return render(request, 'manager/manager_information.html', context) # 將該用戶的個人信息再次傳到前端頁面
用戶密碼修改
views.py中用戶密碼修改代碼段
def change_password(request):#修改密碼 result = User.objects.filter(account=account).first() password = result.user_password if request.method == "GET": #此部分是當每次點擊側(cè)邊導航欄的“修改密碼”選項時,顯示該界面 return render(request,'student/change_password.html',context={"password":password,"name":global_sname}) else:#此部分是在change_password.html頁面中點擊保存按鈕時完成修改密碼的操作 oldPassword = request.POST.get("oldPassword") newPassword = request.POST.get("newPassword") reNewPassword = request.POST.get("reNewPassword")#以下是先判斷輸入的舊密碼是否正確,并且兩次輸入的密碼是否一致且都不為空 if password == oldPassword and newPassword == reNewPassword and newPassword and reNewPassword: User.objects.filter(account=account).update(user_password = newPassword)#更新該用戶的密碼 password = newPassword return render(request, 'student/change_password.html', context={"password": password, "name": global_sname}) def change_manager_password(request):#修改管理員的密碼 result = User.objects.filter(account=account).first() password = result.user_password if request.method == "GET":#此部分是當每次點擊側(cè)邊導航欄的“修改密碼”選項時,顯示該界面 return render(request,'manager/change_manager_password.html',context={"password":password,"name":global_mname}) else:#此部分是在change_manager_password.html頁面中點擊保存按鈕時完成修改密碼的操作 oldPassword = request.POST.get("oldPassword") newPassword = request.POST.get("newPassword") reNewPassword = request.POST.get("reNewPassword")#以下是先判斷輸入的舊密碼是否正確,并且兩次輸入的密碼是否一致且都不為空 if password == oldPassword and newPassword == reNewPassword and newPassword and reNewPassword: User.objects.filter(account=account).update(user_password = newPassword)#更新該用戶的密碼 password = newPassword return render(request, 'manager/change_manager_password.html', context={"password": password, "name": global_mname})
圖書館里模塊實現(xiàn)的功能與我們?nèi)粘D書館的借閱系統(tǒng)相似,學生端包括書籍查詢、書籍借閱、書記歸還;管理員端包括書籍采購、書籍信息修改等更多擴展功能
書籍查詢及借閱歸還,可選擇按書籍名或類型查找
views代碼段
def search_book(request):#查找書籍 if request.method == "GET":#此部分是當用戶每次點擊側(cè)邊導航欄的“查找書籍”選項時,都要顯示出所有書籍資料 books = Book.objects.all() types = Type.objects.all() return render(request, 'student/search_book.html',context={"books": books,"types":types,"name":global_sname }) # 向前端傳遞所有查找到的書籍信息的集合 else:#student/search_book.html頁面的第56行中通過post方式的“搜索”按鈕跳轉(zhuǎn)到此處,即完成搜索操作 book_name = request.POST.get("book_name") type_id = request.POST.get("type_id") types = Type.objects.all() if book_name:#如果書名非空,則按書名查找 book_result = Book.objects.filter(book_name=book_name) if book_result:#如果找到的結(jié)果集非空,則輸出 return render(request,'student/search_book.html',context={"books":book_result,"types":types,"name":global_sname}) else:#若搜索的結(jié)果集為0,那么輸出未找到該本書! book_result = Book.objects.all() return render(request, 'student/search_book.html',context={"books": book_result, "types": types, "name": global_sname, "status": 0}) else: if type_id:#如果獲取的類型輸入框內(nèi)容不為空,則按類型查找 book_result = Book.objects.filter(book_type=type_id) if book_result:#如果找到的結(jié)果集非空,則輸出 return render(request, 'student/search_book.html', context={"books": book_result,"types":types,"name":global_sname}) else:#若搜索的結(jié)果集為0,那么輸出未找到類型的書! book_result = Book.objects.all() return render(request, 'student/search_book.html',context={"books": book_result, "types": types, "name": global_sname,"status":1}) else:#都為空,則顯示空列表 return render(request, 'student/search_book.html') def borrow_book(request): book_ISBN = request.GET.get("book_ISBN") result = Book.objects.filter(ISBN=book_ISBN).first() books = Book.objects.all() types = Type.objects.all() if result.book_rest:#如果可借數(shù)不為0,則進行book_rest-- rest = result.book_rest-1 Book.objects.filter(ISBN=book_ISBN).update(book_rest=rest) now_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")#獲取當前借書的系統(tǒng)時間 student = Student.objects.filter(student_tel=account).first() Borrow.objects.create(student_id=student.student_id,student_name=student.student_name,student_tel=account,book_id=book_ISBN,book_name=result.book_name,borrow_time=now_time,rest_time=60) return render(request, 'student/search_book.html',context={"books": books, "types": types, "name": global_sname}) # 向前端傳遞所有查找到的書籍信息的集合 else:#可借數(shù)為0,則不予借出 return render(request, 'student/search_book.html',context={"books": books, "types": types, "name": global_sname}) # 向前端傳遞所有查找到的書籍信息的集合 def borrow_record(request):#借書記錄 if request.method == "GET": records = Borrow.objects.filter(student_tel=account)#把當前用戶的借閱記錄搜索出來 #計算剩余天數(shù) for record in records: borrow_t = record.borrow_time #獲取借閱時間如:2019-11-1 11:40 print(borrow_t) str1 = borrow_t.split(' ') # 先用空格分割該時間字符串,并保存到列表,str1[0]='2019-11-1' ,str1[1]='11:40' str2 = str1[0].split('-') #再講時間按'-'分割開,得到str2,str2[0]='2019',str2[1]='11',str2[2]='1' borrow_time = datetime.date(int(str2[0]), int(str2[1]), int(str2[2]))#利用date函數(shù)得到相對應(yīng)的借閱時間 now_time = datetime.date(datetime.datetime.now().year, datetime.datetime.now().month, datetime.datetime.now().day) # 獲取當前日期 rest_day = 60 - (now_time - borrow_time).days #最多借閱60天 print(rest_day) if rest_day>=0: Borrow.objects.filter(borrow_time = record.borrow_time).update(rest_time = rest_day) else: Borrow.objects.filter(borrow_time = record.borrow_time).update(rest_time = 0) return render(request,'student/borrow_record.html',context={"records":records,"name":global_sname}) def return_book(request):#還書操作,在borrow_record.html頁面中點擊還書按鈕后跳轉(zhuǎn)到此處 borrow_id = request.GET.get("borrow_id") result1 = Borrow.objects.filter(id = borrow_id).first() result2 = Book.objects.filter(ISBN = result1.book_id).first() rest = result2.book_rest+1 #還書后庫存+1 Book.objects.filter(ISBN = result2.ISBN).update(book_rest = rest) Borrow.objects.filter(id=borrow_id).delete() # 當點擊還書按鈕后,刪除該用戶的借閱記錄 records = Borrow.objects.filter(student_tel=account) # 把當前用戶的借閱記錄搜索出來 return render(request, 'student/borrow_record.html', context={"records": records, "name": global_sname})
書籍采購(既書籍入庫)以及書籍信息修改等
views代碼段
def manage_book(request):#管理書籍 if request.method == "GET": # 此部分是當用戶每次點擊側(cè)邊導航欄的“管理書籍”選項時,都要顯示出所有書籍資料 books = Book.objects.all() types = Type.objects.all() return render(request, 'manager/manage_book.html',context={"books": books, "types": types, "name": global_mname}) # 向前端傳遞所有查找到的書籍信息的集合 else: # 在manager/manage_bok.html頁面中通過post方式的“搜索”按鈕跳轉(zhuǎn)到此處,即完成搜索操作 book_name = request.POST.get("book_name") type_id = request.POST.get("type_id") types = Type.objects.all() if book_name: # 如果書名非空,則按書名查找 book_result = Book.objects.filter(book_name=book_name) if book_result: # 如果找到的結(jié)果集非空,則輸出 return render(request, 'manager/manage_book.html',context={"books": book_result, "types": types, "name": global_mname}) else: # 若搜索的結(jié)果集為0,那么輸出未找到該本書! book_result = Book.objects.all() return render(request, 'manager/manage_book.html', context={"books": book_result, "types": types, "name": global_mname, "status": 0}) else: if type_id: # 如果獲取的類型輸入框內(nèi)容不為空,則按類型查找 book_result = Book.objects.filter(book_type=type_id) if book_result: # 如果找到的結(jié)果集非空,則輸出 return render(request, 'manager/manage_book.html', context={"books": book_result, "types": types, "name": global_mname}) else: # 若搜索的結(jié)果集為0,那么輸出未找到類型的書! book_result = Book.objects.all() return render(request, 'manager/manage_book.html', context={"books": book_result, "types": types, "name": global_mname, "status": 1}) else: # 都為空,則顯示空列表 return render(request, 'manager/manage_book.html') def add_book(request):#增加書籍的館藏數(shù)量 if request.method == "GET": ISBN = request.GET.get("book_ISBN1") result = Book.objects.filter(ISBN=ISBN).first() number = result.book_number+1 #讓該書本的館藏數(shù)量和可借數(shù)++ rest = result.book_rest+1 Book.objects.filter(ISBN=ISBN).update(book_number = number,book_rest = rest) books = Book.objects.all() types = Type.objects.all() return render(request, 'manager/manage_book.html',context={"books": books, "types": types, "name": global_mname}) # 向前端傳遞所有查找到的書籍信息的集合 def reduce_book(request):#減少書籍的館藏數(shù)量 if request.method == "GET": ISBN = request.GET.get("book_ISBN2") result = Book.objects.filter(ISBN=ISBN).first() number = result.book_number - 1 #讓該書本的館藏數(shù)量和可借數(shù)-- rest = result.book_rest -1 Book.objects.filter(ISBN=ISBN).update(book_number = number,book_rest = rest) books = Book.objects.all() types = Type.objects.all() return render(request, 'manager/manage_book.html',context={"books": books, "types": types, "name": global_mname}) # 向前端傳遞所有查找到的書籍信息的集合 def delete_book(request):#清空該書籍 if request.method == "GET": ISBN = request.GET.get("ISBN") print(ISBN) Book.objects.filter(ISBN = ISBN).delete()#在book表里刪除該條記錄 books = Book.objects.all() types = Type.objects.all() return render(request, 'manager/manage_book.html',context={"books": books, "types": types, "name": global_mname}) # 向前端傳遞所有查找到的書籍信息的集合 def alter_book(request):#修改書本詳情 types = Type.objects.all() if request.method == "GET":#此部分是當用戶在manage_book.html頁面中點擊修改書籍是執(zhí)行,目的是顯示當前書本的信息 ISBN = request.GET.get("book_ISBN3") result = Book.objects.filter(ISBN=ISBN).first() context={ "ISBN": result.ISBN, "book_name": result.book_name, "book_author": result.book_author, "book_publisher": result.book_publisher, "book_version": result.book_version, "book_price": result.book_price, "book_number": result.book_number, "book_rest": result.book_rest, "book_place": result.book_place, "type_name": result.book_type.type_name, "name": global_sname, "types": types } return render(request, 'manager/alter_book.html',context) # 向前端傳遞該書籍的所有信息 else:#此部分是當用戶在alter_book.html頁面中點擊保存按鈕后重新更新用戶修改后的信息 ISBN = request.POST.get("ISBN") book_name = request.POST.get("book_name") book_author = request.POST.get("book_author") book_publisher = request.POST.get("book_publisher") book_version = request.POST.get("book_version") book_price = request.POST.get("book_price") book_number = request.POST.get("book_number") book_rest = request.POST.get("book_rest") book_place = request.POST.get("book_place") type_name = request.POST.get("type_name") if book_number.isdigit() and book_rest.isdigit(): # 判斷輸入的館藏數(shù)和可借數(shù)是否為數(shù)字 type = Type.objects.filter(type_name=type_name).first() # 書籍類型是外鍵 Book.objects.filter(ISBN=ISBN).update( book_name=book_name, book_author=book_author, book_publisher=book_publisher, book_version = book_version, book_price = book_price, book_number=book_number, book_rest=book_rest, book_place = book_place, book_type=type) # 在book表里更新剛才修改的書本信息 context = { #把修改后的內(nèi)容顯示出來 "ISBN": ISBN, "book_name": book_name, "book_author": book_author, "book_publisher": book_publisher, "book_version": book_version, "book_price": book_price, "book_number": book_number, "book_rest": book_rest, "book_place": book_place, "type_name": type_name, "name": global_sname, "types": types } return render(request, 'manager/alter_book.html',context) # 重新向前端傳遞該書籍的所有信息 else: result = Book.objects.filter(ISBN=ISBN).first() context = { "ISBN": result.ISBN, "book_name": result.book_name, "book_author": result.book_author, "book_publisher": result.book_publisher, "book_version": result.book_version, "book_price": result.book_price, "book_number": result.book_number, "book_rest": result.book_rest, "book_place": result.book_place, "type_name": result.book_type.type_name, "name": global_sname, "types": types } return render(request, 'manager/alter_book.html', context) # 向前端傳遞該書籍的所有信息 def add_new_book(request):#添加新書籍 types = Type.objects.all() if request.method == "GET":#此部分是當每次點擊側(cè)邊導航欄的“采購書籍”選項時,顯示該界面 return render(request, 'manager/add_new_book.html', context={ "name": global_mname,"types":types}) else:#此部分是在add_new_book.html頁面中點擊確認按鈕后完成的添加書籍操作 ISBN = request.POST.get("ISBN")#獲取用戶在前端輸入框中的數(shù)據(jù) book_name = request.POST.get("book_name") book_author = request.POST.get("book_author") book_publisher = request.POST.get("book_publisher") book_version = request.POST.get("book_version") book_price = request.POST.get("book_price") book_number = request.POST.get("book_number") book_rest = request.POST.get("book_rest") book_place = request.POST.get("book_place") type_name = request.POST.get("type_name") if book_number.isdigit() and book_rest.isdigit():#判斷輸入的館藏數(shù)和可借數(shù)是否為數(shù)字 type = Type.objects.filter(type_name = type_name).first()#書籍類型是外鍵 Book.objects.create(ISBN=ISBN,book_name=book_name,book_author=book_author,book_publisher=book_publisher,book_version=book_version, book_price=book_price,book_number=book_number,book_rest=book_rest,book_place=book_place,book_type=type)#在book表里添加新記錄 return render(request, 'manager/add_new_book.html', context={ "name": global_mname,"types":types}) else: return render(request, 'manager/add_new_book.html', context={ "name": global_mname,"types":types})
數(shù)據(jù)管理模塊主要是設(shè)計數(shù)據(jù)庫的存儲和操作,django的ROM機制可以讓用戶在models上面編寫要創(chuàng)建的數(shù)據(jù)表類型,通過執(zhí)行遷移,直接在數(shù)據(jù)庫創(chuàng)建數(shù)據(jù)庫表
models.py代碼段
from django.db import models class User(models.Model): #用戶表 account=models.CharField(max_length = 20,primary_key=True)#賬號 user_password=models.CharField(max_length = 20)#用戶密碼 user_identity=models.CharField(max_length = 20)#用戶身份 class Student(models.Model): #學生信息表 student_id=models.CharField(max_length = 20,primary_key=True)#學號 主鍵 student_name=models.CharField(max_length=20)#姓名 student_tel=models.CharField(max_length = 20)#電話 student_major=models.CharField(max_length = 20)#院系 student_email=models.CharField(max_length = 50)#郵箱 class Manager(models.Model): #圖書管理員信息表 manager_id=models.CharField(max_length = 20,primary_key=True)#工號 主鍵 manager_name=models.CharField(max_length=20)#姓名 manager_tel=models.CharField(max_length = 20)#電話 manager_email=models.CharField(max_length = 50)#郵箱 manager_stack=models.CharField(max_length = 20)#管理書庫 class Type(models.Model):#書籍類型表 type_id= models.CharField(max_length=20,primary_key=True) # 類型編號,主鍵 type_name = models.CharField(max_length=20) # 類型名稱 class Book(models.Model):#書本信息表 ISBN= models.CharField(max_length = 20,primary_key=True) # 國際標準書號 主鍵 book_name = models.CharField(max_length=20) # 書名 book_author = models.CharField(max_length=20) # 作者 book_publisher = models.CharField(max_length=20) # 出版社 book_version = models.CharField(max_length=20) # 版本 book_price = models.CharField(max_length=20) # 價格 book_number = models.IntegerField() # 總庫存數(shù)(館藏數(shù)) book_rest = models.IntegerField() # 可借數(shù) book_place = models.CharField(max_length=20) # 所屬書庫 book_type = models.ForeignKey(Type, on_delete=models.CASCADE)#書籍類型 class Borrow(models.Model):#借閱表 student_id= models.CharField(max_length=20) # 借書人學號 student_name = models.CharField(max_length=20) # 借書人姓名 student_tel = models.CharField(max_length=20) # 借書人聯(lián)系方式 book_id = models.CharField(max_length=20) # 書籍編號 book_name = models.CharField(max_length=20) # 書名 borrow_time = models.CharField(max_length=20) # 借書時間 rest_time = models.IntegerField() # 剩余天數(shù)
settings.py關(guān)于數(shù)據(jù)庫的相關(guān)設(shè)定
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'Library', #數(shù)據(jù)庫名字 'USER': 'xxxx', #用戶名 'PASSWORD': 'xxxx',#密碼 'HOST': 'localhost', #本地主機 'PORT': '3306' #端口號 } }
前端模塊是向用戶展示的用戶界面,通常保存在templates文件夾下,后端通過與前端的數(shù)據(jù)進行交互,通過路由返回具體的頁面實現(xiàn)渲染。
templates文件夾目錄
urls.py路由路徑
from django.contrib import admin from django.urls import path,include from MyApp import views as App_views urlpatterns = [ path('admin/', admin.site.urls), path('MyApp/',include('MyApp.urls')), path('login/',App_views.login), path('student_register/',App_views.student_register), path('manager_register/',App_views.manager_register), path('login_judge/', App_views.login_judge), path('student_information/',App_views.student_information), path('search_book/',App_views.search_book), path('borrow_record/',App_views.borrow_record), path('change_password/',App_views.change_password), path('borrow_book/',App_views.borrow_book), path('return_book/',App_views.return_book), path('manager_information/', App_views.manager_information), path('manage_book/', App_views.manage_book), path('delete_book/', App_views.delete_book), path('add_book/', App_views.add_book), path('reduce_book/', App_views.reduce_book), path('change_manager_password/', App_views.change_manager_password), path('add_new_book/', App_views.add_new_book), path('alter_book/', App_views.alter_book), path('',App_views.login), ]
通過django創(chuàng)建的數(shù)據(jù)庫表
到此,相信大家對“Django圖書管理系統(tǒng)怎么實現(xiàn)”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學習!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。