程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Django-圖書管理系統(含源碼)

編輯:Python

前段時間翻文件發現了以前學習python和django時做的一個系統,當時的想法是將這玩意做出來應付web開發大作業、課程設計作業甚至是畢設用的,實際上也確實應付了課程設計,功能雖然不算多,但是應付課程設計或者大作業綽綽有余了。

項目使用python開發,采用Django框架,數據庫采用MySQL,根據用戶人員的不同分成兩套系統,分別是學生系統和管理員系統,功能模塊具體分成四個,分別是用戶管理模塊、圖書管理模塊、數據管理模塊、前端模塊。

1、用戶管理模塊

用戶管理模塊實現的功能包括用戶注冊(分為學生注冊和管理員注冊)、用戶信息修改、用戶登錄和判定

用戶注冊和登錄

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: # 判斷該賬戶是否存在(即判斷是否注冊過),如果後台存在記錄,則返回相應的提示語句
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: # 判斷該賬戶是否存在(即判斷是否注冊過),如果後台存在記錄,則返回相應的提示語句
context["info"] = "該賬戶已注冊!!!"
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) # 跳轉到學生主頁界面
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) # 跳轉到管理員主頁界面
else: # 如果不一致則返回相應提示語句
context = {
"info": "密碼錯誤!!!",
"status": 2
}
return render(request, 'login.html', context=context) # 密碼錯誤回到登入界面
else: # 如果不存在該用戶則返回相應的提示語句
context = {
"info": "該賬戶不存在!!!",
"status": 3
}
return render(request, 'login.html', context=context) # 賬戶不存在則繼續回到登入界面

用戶信息管理

views.py中用戶信息管理代碼段

def student_information(request):#個人信息
if request.method == "GET": #此部分是當每次點擊側邊導航欄的“個人信息”選項時,都重新顯示該用戶的個人資料
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方式的“保存”按鈕跳轉到此處,即完成更新數據操作(保存)
email = request.POST.get("email") # 獲取郵箱
Student.objects.filter(student_tel=account).update(student_email=email)#更新數據
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": #此部分是當每次點擊側邊導航欄的“個人信息”選項時,都重新顯示該管理員的個人資料
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方式的“保存”按鈕跳轉到此處,即完成更新數據操作(保存)
stack = request.POST.get("stack") # 獲取書庫信息
email = request.POST.get("email") # 獲取郵箱
Manager.objects.filter(manager_tel=account).update(manager_email=email,manager_stack=stack)#更新數據
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": #此部分是當每次點擊側邊導航欄的“修改密碼”選項時,顯示該界面
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":#此部分是當每次點擊側邊導航欄的“修改密碼”選項時,顯示該界面
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})

2、圖書管理模塊

圖書館裡模塊實現的功能與我們日常圖書館的借閱系統相似,學生端包括書籍查詢、書籍借閱、書記歸還;管理員端包括書籍采購、書籍信息修改等更多擴展功能

書籍查詢及借閱歸還,可選擇按書籍名或類型查找

views代碼段

def search_book(request):#查找書籍
if request.method == "GET":#此部分是當用戶每次點擊側邊導航欄的“查找書籍”選項時,都要顯示出所有書籍資料
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方式的“搜索”按鈕跳轉到此處,即完成搜索操作
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:#如果找到的結果集非空,則輸出
return render(request,'student/search_book.html',context={"books":book_result,"types":types,"name":global_sname})
else:#若搜索的結果集為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:#如果獲取的類型輸入框內容不為空,則按類型查找
book_result = Book.objects.filter(book_type=type_id)
if book_result:#如果找到的結果集非空,則輸出
return render(request, 'student/search_book.html', context={"books": book_result,"types":types,"name":global_sname})
else:#若搜索的結果集為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:#如果可借數不為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")#獲取當前借書的系統時間
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:#可借數為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)#把當前用戶的借閱記錄搜索出來
#計算剩余天數
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函數得到相對應的借閱時間
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頁面中點擊還書按鈕後跳轉到此處
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": # 此部分是當用戶每次點擊側邊導航欄的“管理書籍”選項時,都要顯示出所有書籍資料
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方式的“搜索”按鈕跳轉到此處,即完成搜索操作
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: # 如果找到的結果集非空,則輸出
return render(request, 'manager/manage_book.html',context={"books": book_result, "types": types, "name": global_mname})
else: # 若搜索的結果集為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: # 如果獲取的類型輸入框內容不為空,則按類型查找
book_result = Book.objects.filter(book_type=type_id)
if book_result: # 如果找到的結果集非空,則輸出
return render(request, 'manager/manage_book.html',
context={"books": book_result, "types": types, "name": global_mname})
else: # 若搜索的結果集為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):#增加書籍的館藏數量
if request.method == "GET":
ISBN = request.GET.get("book_ISBN1")
result = Book.objects.filter(ISBN=ISBN).first()
number = result.book_number+1 #讓該書本的館藏數量和可借數++
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):#減少書籍的館藏數量
if request.method == "GET":
ISBN = request.GET.get("book_ISBN2")
result = Book.objects.filter(ISBN=ISBN).first()
number = result.book_number - 1 #讓該書本的館藏數量和可借數--
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頁面中點擊修改書籍是執行,目的是顯示當前書本的信息
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(): # 判斷輸入的館藏數和可借數是否為數字
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 = { #把修改後的內容顯示出來
"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":#此部分是當每次點擊側邊導航欄的“采購書籍”選項時,顯示該界面
return render(request, 'manager/add_new_book.html', context={ "name": global_mname,"types":types})
else:#此部分是在add_new_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():#判斷輸入的館藏數和可借數是否為數字
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、數據管理模塊

數據管理模塊主要是設計數據庫的存儲和操作,django的ROM機制可以讓用戶在models上面編寫要創建的數據表類型,通過執行遷移,直接在數據庫創建數據庫表

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() # 總庫存數(館藏數)
book_rest = models.IntegerField() # 可借數
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) # 借書人聯系方式
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() # 剩余天數

settings.py關於數據庫的相關設定

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'Library', #數據庫名字
'USER': 'xxxx', #用戶名
'PASSWORD': 'xxxx',#密碼
'HOST': 'localhost', #本地主機
'PORT': '3306' #端口號
}
}

4、前端模塊

前端模塊是向用戶展示的用戶界面,通常保存在templates文件夾下,後端通過與前端的數據進行交互,通過路由返回具體的頁面實現渲染。

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創建的數據庫表

視頻演示鏈接:

圖書管理系統_哔哩哔哩_bilibili

源代碼獲取可私信或+QQ:1834661953

先自我介紹一下,小編13年上師交大畢業,曾經在小公司待過,去過華為OPPO等大廠,18年進入阿裡,直到現在。深知大多數初中級java工程師,想要升技能,往往是需要自己摸索成長或是報班學習,但對於培訓機構動則近萬元的學費,著實壓力不小。自己不成體系的自學效率很低又漫長,而且容易碰到天花板技術停止不前。因此我收集了一份《java開發全套學習資料》送給大家,初衷也很簡單,就是希望幫助到想自學又不知道該從何學起的朋友,同時減輕大家的負擔。添加下方名片,即可獲取全套學習資料哦


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved