Diango也是由python進(jìn)行編寫的,它的應(yīng)用范圍也是比較的廣泛的,可以用來(lái)進(jìn)行編譯各種管理系統(tǒng)。那么,怎么使用Django去編寫圖書管理系統(tǒng)呢?為了解答各位讀者的困惑,下面小編就給大家一步一步的列出了詳細(xì)的步驟。
項(xiàng)目使用python開發(fā),采用Django框架,數(shù)據(jù)庫(kù)采用MySQL,根據(jù)用戶人員的不同分成兩套系統(tǒng),分別是學(xué)生系統(tǒng)和管理員系統(tǒng),功能模塊具體分成四個(gè),分別是用戶管理模塊、圖書管理模塊、數(shù)據(jù)管理模塊、前端模塊。
1、用戶管理模塊
用戶管理模塊實(shí)現(xiàn)的功能包括用戶注冊(cè)(分為學(xué)生注冊(cè)和管理員注冊(cè))、用戶信息修改、用戶登錄和判定
用戶注冊(cè)和登錄
views.py中用戶注冊(cè)及登陸判定代碼段
def login(request):#登錄 return render(request,'login.html') def student_register(request):#學(xué)生注冊(cè) name=request.POST.get("student_name")#獲取學(xué)生輸入的姓名 id=request.POST.get("student_id")#獲取學(xué)生輸入的學(xué)號(hào) major=request.POST.get("student_major")#獲取學(xué)生輸入的學(xué)院 email=request.POST.get("student_email")#獲取學(xué)生輸入的郵箱 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)#在學(xué)生表中搜索該學(xué)號(hào)的記錄 context={} if len(result1)==1:#判斷該賬戶是否存在(即判斷是否注冊(cè)過(guò)),如果后臺(tái)存在記錄,則返回相應(yīng)的提示語(yǔ)句 context["info"]="該賬戶已注冊(cè)!??!" context["status"]=0#零表示注冊(cè)失敗 return render(request,'login.html',context=context) else:#該賬戶是新用戶 if len(result2)==1:#判斷該學(xué)號(hào)是否有學(xué)生已使用 context["info"]="該學(xué)號(hào)已占用?。?!" context["status"]=4 return render(request,'login.html',context=context) else: User.objects.create(account=telephone,user_password=password,user_identity='學(xué)生')#用create為user表添加一條記錄 Student.objects.create(student_name=name,student_id=id,student_major=major,student_tel=telephone,student_email=email)#用create為student表添加一條記錄 context["info"]="注冊(cè)成功!" context["status"]=1#1表示注冊(cè)成功 return render(request,'login.html',context=context) def manager_register(request):#管理員注冊(cè) name=request.POST.get("manager_name")#獲取管理員輸入的姓名 id=request.POST.get("manager_id")#獲取管理員輸入的工號(hào) stack=request.POST.get("manager_stack")#獲取管理員輸入的書庫(kù) 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)#在管理員表中搜索該工號(hào)的使用記錄 context={} if len(result1)==1:#判斷該賬戶是否存在(即判斷是否注冊(cè)過(guò)),如果后臺(tái)存在記錄,則返回相應(yīng)的提示語(yǔ)句 context["info"]="該賬戶已注冊(cè)?。?!" context["status"]=0#零表示注冊(cè)失敗 return render(request,'login.html',context=context) else:#該賬戶是新用戶 if len(result2)==1:#判斷該工號(hào)號(hào)是否有管理員已使用 context["info"]="該工號(hào)已占用?。?!" 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"]="注冊(cè)成功!" context["status"]=1#1表示注冊(cè)成功 return render(request,'login.html',context=context) def login_judge(request):#登入判定 global account,global_sname,global_mname#定義全局變量account,存儲(chǔ)該用戶的賬戶,global_sname保存一下該學(xué)生的姓名,global_mname保存一下該學(xué)生的姓名 account=request.POST.get("telephone")#獲取前端輸入的賬戶(手機(jī)號(hào)) user_password=request.POST.get("password") result1=User.objects.filter(account=account)#在user表里檢索是否存在該賬戶 if len(result1)==1:#判斷后臺(tái)是否存在該用戶,有則進(jìn)一步判斷密碼是否正確 password=result1[0].user_password#獲取后臺(tái)的密碼 identity=result1[0].user_identity#獲取該賬戶的身份信息 if user_password==password:#將用戶輸入的密碼和后臺(tái)密碼進(jìn)行比對(duì),如何正確,判斷該賬戶身份 if identity=='學(xué)生': result2=Student.objects.filter(student_tel=account) global_sname=result2[0].student_name#用全局變量保存一下該學(xué)生的姓名 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)到學(xué)生主頁(yè)界面 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)到管理員主頁(yè)界面 else:#如果不一致則返回相應(yīng)提示語(yǔ)句 context={ "info":"密碼錯(cuò)誤?。?!", "status":2 } return render(request,'login.html',context=context)#密碼錯(cuò)誤回到登入界面 else:#如果不存在該用戶則返回相應(yīng)的提示語(yǔ)句 context={ "info":"該賬戶不存在?。?!", "status":3 } return render(request,'login.html',context=context)#賬戶不存在則繼續(xù)回到登入界面
用戶信息管理
views.py中用戶信息管理代碼段
def student_information(request):#個(gè)人信息 if request.method=="GET":#此部分是當(dāng)每次點(diǎn)擊側(cè)邊導(dǎo)航欄的“個(gè)人信息”選項(xiàng)時(shí),都重新顯示該用戶的個(gè)人資料 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)#將該用戶的個(gè)人信息再次傳到前端頁(yè)面 else:#在student_information.html頁(yè)面的第44行中通過(guò)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)#將該用戶的個(gè)人信息再次傳到前端頁(yè)面 def manager_information(request):#個(gè)人信息 if request.method=="GET":#此部分是當(dāng)每次點(diǎn)擊側(cè)邊導(dǎo)航欄的“個(gè)人信息”選項(xiàng)時(shí),都重新顯示該管理員的個(gè)人資料 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)#將該用戶的個(gè)人信息再次傳到前端頁(yè)面 else:#在manager_information.html頁(yè)面的第44行中通過(guò)post方式的“保存”按鈕跳轉(zhuǎn)到此處,即完成更新數(shù)據(jù)操作(保存) stack=request.POST.get("stack")#獲取書庫(kù)信息 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)#將該用戶的個(gè)人信息再次傳到前端頁(yè)面
用戶密碼修改
views.py中用戶密碼修改代碼段
def change_password(request):#修改密碼 result=User.objects.filter(account=account).first() password=result.user_password if request.method=="GET":#此部分是當(dāng)每次點(diǎn)擊側(cè)邊導(dǎo)航欄的“修改密碼”選項(xiàng)時(shí),顯示該界面 return render(request,'student/change_password.html',context={"password":password,"name":global_sname}) else:#此部分是在change_password.html頁(yè)面中點(diǎn)擊保存按鈕時(shí)完成修改密碼的操作 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":#此部分是當(dāng)每次點(diǎn)擊側(cè)邊導(dǎo)航欄的“修改密碼”選項(xiàng)時(shí),顯示該界面 return render(request,'manager/change_manager_password.html',context={"password":password,"name":global_mname}) else:#此部分是在change_manager_password.html頁(yè)面中點(diǎn)擊保存按鈕時(shí)完成修改密碼的操作 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})
2、圖書管理模塊
圖書館里模塊實(shí)現(xiàn)的功能與我們?nèi)粘D書館的借閱系統(tǒng)相似,學(xué)生端包括書籍查詢、書籍借閱、書記歸還;管理員端包括書籍采購(gòu)、書籍信息修改等更多擴(kuò)展功能
書籍查詢及借閱歸還,可選擇按書籍名或類型查找
views代碼段
def search_book(request):#查找書籍 if request.method=="GET":#此部分是當(dāng)用戶每次點(diǎn)擊側(cè)邊導(dǎo)航欄的“查找書籍”選項(xiàng)時(shí),都要顯示出所有書籍資料 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頁(yè)面的第56行中通過(guò)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,則進(jìn)行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")#獲取當(dāng)前借書的系統(tǒng)時(shí)間 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)#把當(dāng)前用戶的借閱記錄搜索出來(lái) #計(jì)算剩余天數(shù) for record in records: borrow_t=record.borrow_time#獲取借閱時(shí)間如:2019-11-1 11:40 print(borrow_t) str1=borrow_t.split('')#先用空格分割該時(shí)間字符串,并保存到列表,str1[0]='2019-11-1',str1[1]='11:40' str2=str1[0].split('-')#再講時(shí)間按'-'分割開,得到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ù)得到相對(duì)應(yīng)的借閱時(shí)間 now_time=datetime.date(datetime.datetime.now().year,datetime.datetime.now().month, datetime.datetime.now().day)#獲取當(dāng)前日期 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頁(yè)面中點(diǎn)擊還書按鈕后跳轉(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#還書后庫(kù)存+1 Book.objects.filter(ISBN=result2.ISBN).update(book_rest=rest) Borrow.objects.filter(id=borrow_id).delete()#當(dāng)點(diǎn)擊還書按鈕后,刪除該用戶的借閱記錄 records=Borrow.objects.filter(student_tel=account)#把當(dāng)前用戶的借閱記錄搜索出來(lái) return render(request,'student/borrow_record.html',context={"records":records,"name":global_sname})
書籍采購(gòu)(既書籍入庫(kù))以及書籍信息修改等
views代碼段
def manage_book(request):#管理書籍 if request.method=="GET":#此部分是當(dāng)用戶每次點(diǎn)擊側(cè)邊導(dǎo)航欄的“管理書籍”選項(xiàng)時(shí),都要顯示出所有書籍資料 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頁(yè)面中通過(guò)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):#增加書籍的館藏?cái)?shù)量 if request.method=="GET": ISBN=request.GET.get("book_ISBN1") result=Book.objects.filter(ISBN=ISBN).first() number=result.book_number+1#讓該書本的館藏?cái)?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):#減少書籍的館藏?cái)?shù)量 if request.method=="GET": ISBN=request.GET.get("book_ISBN2") result=Book.objects.filter(ISBN=ISBN).first() number=result.book_number-1#讓該書本的館藏?cái)?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":#此部分是當(dāng)用戶在manage_book.html頁(yè)面中點(diǎn)擊修改書籍是執(zhí)行,目的是顯示當(dāng)前書本的信息 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:#此部分是當(dāng)用戶在alter_book.html頁(yè)面中點(diǎn)擊保存按鈕后重新更新用戶修改后的信息 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():#判斷輸入的館藏?cái)?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)容顯示出來(lá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":#此部分是當(dāng)每次點(diǎn)擊側(cè)邊導(dǎo)航欄的“采購(gòu)書籍”選項(xiàng)時(shí),顯示該界面 return render(request,'manager/add_new_book.html',context={"name":global_mname,"types":types}) else:#此部分是在add_new_book.html頁(yè)面中點(diǎn)擊確認(rèn)按鈕后完成的添加書籍操作 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():#判斷輸入的館藏?cái)?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})
3、數(shù)據(jù)管理模塊
數(shù)據(jù)管理模塊主要是設(shè)計(jì)數(shù)據(jù)庫(kù)的存儲(chǔ)和操作,django的ROM機(jī)制可以讓用戶在models上面編寫要?jiǎng)?chuàng)建的數(shù)據(jù)表類型,通過(guò)執(zhí)行遷移,直接在數(shù)據(jù)庫(kù)創(chuàng)建數(shù)據(jù)庫(kù)表
models.py代碼段 from django.db import models class User(models.Model):#用戶表 account=models.CharField(max_length=20,primary_key=True)#賬號(hào) user_password=models.CharField(max_length=20)#用戶密碼 user_identity=models.CharField(max_length=20)#用戶身份 class Student(models.Model):#學(xué)生信息表 student_id=models.CharField(max_length=20,primary_key=True)#學(xué)號(hào)主鍵 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)#工號(hào)主鍵 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)#管理書庫(kù) class Type(models.Model):#書籍類型表 type_id=models.CharField(max_length=20,primary_key=True)#類型編號(hào),主鍵 type_name=models.CharField(max_length=20)#類型名稱 class Book(models.Model):#書本信息表 ISBN=models.CharField(max_length=20,primary_key=True)#國(guó)際標(biāo)準(zhǔn)書號(hào)主鍵 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)#價(jià)格 book_number=models.IntegerField()#總庫(kù)存數(shù)(館藏?cái)?shù)) book_rest=models.IntegerField()#可借數(shù) book_place=models.CharField(max_length=20)#所屬書庫(kù) book_type=models.ForeignKey(Type,on_delete=models.CASCADE)#書籍類型 class Borrow(models.Model):#借閱表 student_id=models.CharField(max_length=20)#借書人學(xué)號(hào) student_name=models.CharField(max_length=20)#借書人姓名 student_tel=models.CharField(max_length=20)#借書人聯(lián)系方式 book_id=models.CharField(max_length=20)#書籍編號(hào) book_name=models.CharField(max_length=20)#書名 borrow_time=models.CharField(max_length=20)#借書時(shí)間 rest_time=models.IntegerField()#剩余天數(shù)
4、前端模塊
前端模塊是向用戶展示的用戶界面,通常保存在templates文件夾下,后端通過(guò)與前端的數(shù)據(jù)進(jìn)行交互,通過(guò)路由返回具體的頁(yè)面實(shí)現(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), ]
通過(guò)django創(chuàng)建的數(shù)據(jù)庫(kù)表
綜上所述,這篇文章就給大家介紹到這里了,希望可以給大家?guī)?lái)更多幫助。
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/128328.html
摘要:兩者相同的地方是都可以將一個(gè)普通函數(shù)變成視圖函數(shù)。不同的是,使用裝飾器定義路由,而使用正則表達(dá)式定義路由。中間什么都沒有,表示這個(gè)正則匹配的是根目錄,。最后修改的網(wǎng)頁(yè)顯示如圖項(xiàng)目框架圖 Django添加路由 與flask一樣,django也需要使用路由將URL與服務(wù)端要執(zhí)行的代碼關(guān)聯(lián)。 兩者相同的地方是都可以將一個(gè)普通函數(shù)變成視圖函數(shù)。不同的是,flask使用裝飾器@app.route...
閱讀 923·2023-01-14 11:38
閱讀 896·2023-01-14 11:04
閱讀 756·2023-01-14 10:48
閱讀 2056·2023-01-14 10:34
閱讀 961·2023-01-14 10:24
閱讀 840·2023-01-14 10:18
閱讀 510·2023-01-14 10:09
閱讀 588·2023-01-14 10:02