import time
from django.http import HttpResponseRedirect
from django.shortcuts import render, redirect
from django.core import paginator
# Create your views here.
from Book.models import Student, Book, UserBookInfo
def index(request):
return render(request,"index.html")
def register(request):
return render(request,"register.html")
def toRegister(request):
# 接收学生注册信息
num=request.POST["num"]
psd=request.POST["psd"]
name=request.POST["name"]
phone=request.POST["phone"]
s=Student.objects.filter(number=num)
if not s:
# 将注册信息添加至数据库中
Student.objects.create(number=num,psd=psd,name=name,phone=phone)
# 回到登录页面
return redirect(index)
else:
return render(request,"registerError.html")
# 保存登录信息
student=[]
def toLogin(request):
# 接收学生的登录信息,并将登录成功的学生信息临时存储
num=request.POST["num"]
psd=request.POST["psd"]
# 根据登录信息查询数据库该学生是否存在
global student
student=Student.objects.filter(number=num,psd=psd)
# 如果能查询到数据,则进入主页
if student:
return redirect(bookList)
else:
return render(request,"loginError.html")
def bookList(request):
try:
ym=request.GET["ym"]
except:
ym=1
# 将所有图书信息查询出来
bookList = Book.objects.all().values()
p=paginator.Paginator(bookList,16)
page=p.get_page(ym)
bookList=page.object_list
yms=p.page_range
for b in bookList:
b["image"] = "img/" + str(b["image"])
return render(request, "home.html", {"student": student[0], "bookList": bookList,"page":page,"yms":yms})
def seach(request):
info=request.POST["seach"]
# 进行模糊查询
bookList=Book.objects.filter(bookName__contains=info).values()
try:
ym = request.GET["ym"]
except:
ym = 1
p = paginator.Paginator(bookList, 16)
page = p.get_page(ym)
bookList = page.object_list
yms = p.page_range
for b in bookList:
b["image"] = "img/" + str(b["image"])
return render(request, "home.html", {"student": student[0], "bookList": bookList, "page": page, "yms": yms})
def bookInfo(request):
id=request.GET["bookid"]
# 根据id获得该对应的图书信息
book=Book.objects.get(id=id)
book.image="img/"+str(book.image)
# 根据当前登录的学生的学号和图书id查询借阅记录表的借阅状态
infos=UserBookInfo.objects.filter(number=student[0].number,bookId=id)
# 如果未查询到,则状态为0,表示未借阅,1表示已借阅,2表示已归还
state= infos[0].state if infos else 0
return render(request,"bookInfo.html",{"student":student[0],"book":book,"state":state})
def addUserBookInfo(request):
id=request.GET["bookid"]
# 根据当前登录的学生的学号和图书id查询借阅记录表的借阅状态
infos = UserBookInfo.objects.filter(number=student[0].id, bookId=id)
# 如果未查询到,则状态为0,表示未借阅,1表示已借阅,2表示已归还
state = infos[0].state if infos else 0
# 获得当前实时时间
year=time.strftime("%Y",time.localtime())
month=time.strftime("%m",time.localtime())
day=time.strftime("%d",time.localtime())
hour=time.strftime("%H",time.localtime())
minute=time.strftime("%M",time.localtime())
second=time.strftime("%S",time.localtime())
dt=f"{year}年{month}月{day}日 {hour}:{minute}:{second}"
if state == 0:
# 表示该学生没有借阅过该书籍,则添加借阅记录
UserBookInfo.objects.create(number=student[0].number,bookId=id,startDate=dt,endDate="",state=1)
elif state == 2:
# 表示该学生借阅过该书籍,并且也归还了
UserBookInfo.objects.create(number=student[0].number, bookId=id, startDate=dt, endDate="", state=1)
return HttpResponseRedirect("/bookInfo/?bookid="+id)
def MyJY(request):
# 从借阅信息表中查询当前学生借阅的所有书籍信息,根据状态为1的借阅状态
jList=UserBookInfo.objects.filter(number=student[0].number,state=1).values()
if jList:
for j in jList:
book=Book.objects.get(id=j["bookId"])
j["image"]="img/"+str(book.image)
j["bookName"]=book.bookName
j["bookAddress"]=book.bookAddress
return render(request,"myJYInfo.html",{"jList":jList,"student":student[0]})
def updateJYInfo(request):
id=request.GET["id"]
# 根据借阅信息id归还图书,修改借阅信息表的借阅状态为2
info=UserBookInfo.objects.filter(id=id)
# 获得当前实时时间
year = time.strftime("%Y", time.localtime())
month = time.strftime("%m", time.localtime())
day = time.strftime("%d", time.localtime())
hour = time.strftime("%H", time.localtime())
minute = time.strftime("%M", time.localtime())
second = time.strftime("%S", time.localtime())
dt = f"{year}年{month}月{day}日 {hour}:{minute}:{second}"
info.update(state=2,endDate=dt)
return redirect(MyJY)
def hisInfo(request):
jList = UserBookInfo.objects.filter(number=student[0].number, state=2).values()
if jList:
for j in jList:
book = Book.objects.get(id=j["bookId"])
j["image"] = "img/" + str(book.image)
j["bookName"] = book.bookName
j["bookAddress"] = book.bookAddress
return render(request, "hisInfo.html", {"jList": jList,"student":student[0]})
def deleteBookInfo(request):
id=request.GET["id"]
# 根据借阅信息id,删除该借阅记录
info=UserBookInfo.objects.filter(id=id)
info.delete()
return redirect(hisInfo)
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于Python语言基础之上,学习django服务器网站开发编程,实现MTV框架模式,完成Sqlite数据库存储数据,读者表,图书表,借阅表,实现登录,注册,图书列表,图书分类,图书详情,图书借阅,图书归还,图书借阅限时归还等功能,界面美观,符合用户的省美要求
资源推荐
资源详情
资源评论
收起资源包目录
基于Django的图书借阅管理系统.rar (111个子文件)
css1.css 2KB
home.html 6KB
index.html 3KB
register.html 3KB
hisInfo.html 2KB
myJYInfo.html 2KB
bookInfo.html 2KB
top.html 1KB
top0.html 874B
foot.html 549B
registerError.html 242B
loginError.html 232B
BookSystem.iml 1KB
img64.jpg 58KB
img65.jpg 51KB
img9.jpg 50KB
img4.jpg 50KB
img55.jpg 49KB
img51.jpg 46KB
img43.jpg 46KB
img1.jpg 45KB
img66.jpg 44KB
img47.jpg 44KB
img7.jpg 42KB
img59.jpg 40KB
img50.jpg 39KB
img11.jpg 39KB
img25.jpg 39KB
img41.jpg 36KB
img31.jpg 34KB
img14.jpg 33KB
img3.jpg 32KB
img60.jpg 32KB
img15.jpg 32KB
img42.jpg 31KB
img44.jpg 31KB
img36.jpg 30KB
img53.jpg 30KB
img10.jpg 29KB
img22.jpg 28KB
img39.jpg 27KB
img33.jpg 27KB
img5.jpg 25KB
img6.jpg 24KB
img19.jpg 24KB
img29.jpg 23KB
img34.jpg 23KB
img23.jpg 22KB
img20.jpg 22KB
img26.jpg 21KB
img38.jpg 21KB
img63.jpg 21KB
img61.jpg 21KB
img24.jpg 21KB
img8.jpg 20KB
img18.jpg 19KB
img40.jpg 18KB
img35.jpg 18KB
img21.jpg 18KB
img13.jpg 17KB
img12.jpg 17KB
img48.jpg 16KB
img32.jpg 16KB
img62.jpg 16KB
img37.jpg 16KB
img2.jpg 15KB
img16.jpg 14KB
img27.jpg 14KB
img57.jpg 14KB
img45.jpg 14KB
img58.jpg 14KB
img30.jpg 13KB
img54.jpg 13KB
img49.jpg 13KB
img28.jpg 13KB
img46.jpg 12KB
img52.jpg 11KB
img56.jpg 9KB
img17.jpg 9KB
foot1.png 119KB
gongan.png 19KB
views.py 6KB
settings.py 3KB
0001_initial.py 2KB
urls.py 2KB
models.py 1KB
manage.py 557B
wsgi.py 413B
apps.py 88B
admin.py 66B
tests.py 63B
__init__.py 0B
__init__.py 0B
__init__.py 0B
views.cpython-37.pyc 5KB
settings.cpython-37.pyc 2KB
urls.cpython-37.pyc 2KB
0001_initial.cpython-37.pyc 1KB
models.cpython-37.pyc 1KB
wsgi.cpython-37.pyc 546B
共 111 条
- 1
- 2
资源评论
- weixin_455049622023-04-09感谢资源主的分享,这个资源对我来说很有用,内容描述详尽,值得借鉴。
- mzm54662023-04-17这个资源值得下载,资源内容详细全面,与描述一致,受益匪浅。
- 2301_766488212023-04-25资源很不错,内容和描述一致,值得借鉴,赶紧学起来!
笔触狂放
- 粉丝: 5088
- 资源: 96
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功