开局 运行-配置数据库
python manage.py makemigrations
python manage.py migrate
res=Book.objects.get(bid=id) 结果出来是对象
Book.objects.filter(bid=id).delete() 结果出来是列表+对象
res=Book.objects.exclude(bid=id) 结果出来是列表+对象
Title{% csrf_token %}
添加书本
***********************************
{% csrf_token %}
查询全部
{% for ii in booklist %}
{{ ii.bid }}
{{ ii.bname }}
{% endfor %}
***********************************
{% csrf_token %}
id:
条件查询
{{ book.bid }}
{{ book.bname }}
***********************************
{% csrf_token %}
ID:
删除
***********************************
{% csrf_token %}
ID:
名字:
修改名字
def bookd(request):
if request.POST:
name=request.POST.get('bname')
book=Book(bname=name)
book.save()
return HttpResponse("")
else:
return render(request,'bookd.html')
def chaxun(request):
if request.POST:
res=Book.objects.all()
print(res)
content={}
content["booklist"]=res
return render(request,'bookd.html',content)
else:
return render(request,'bookd.html')
def chaxun2(request):
if request.POST:
id=request.POST.get('bid')
res=Book.objects.get(bid=id)
content2 = {}
content2["book"] = res
return render(request, 'bookd.html', content2)
else:
return render(request,'bookd.html')
def shanchu(request):
if request.POST:
id=request.POST.get('bid')
Book.objects.filter(bid=id).delete()
return HttpResponse("")
else:
return render(request,'bookd.html')
def xiugai(request):
if request.POST:
id=request.POST.get('bid')
name = request.POST.get('name')
Book.objects.filter(bid=id).update(bname=name)
return HttpResponse("")
else:
return render(request,'bookd.html')
def chaxun3(request):
if request.POST:
id=request.POST.get('bid')
res=Book.objects.exclude(bid=id)
print(res)
content2 = {}
content2["booklists"] = res
return render(request, 'bookd.html', content2)
else:
return render(request,'bookd.html')