图书管理系统进行增、删、改、查
(1)、增加一个添加数据的按钮
-
新增书籍
在index app下的view.py 视图文件中输入:
def addbook(request):
if request.method == ‘POST’:
try:
id = request.POST.get(“id”)
number = request.POST.get(“number”)
category = request.POST.get(“category”)
name = request.POST.get(“name”)
author = request.POST.get(“author”)
press = request.POST.get(“press”)
price = request.POST.get(“price”)
Book.objects.filter(id=id).create(number=number, category=category, name=name, author=author, press=press, price=price)
return redirect(“…/…/books”)
except Exception as e:
print(e)return render(request, ‘addbook.html’)
-
在urls主路由中配置: