查询名字叫xxx的书
from app01 import models
def books(request):
# models.Book.objects.create(name='xxx',price=10.34,publish='南京出版社')
#
#
# book=models.Book(name='yyy',price=11.34,publish='南京出版社')
# book.save()
# 查询所有
res=models.Book.objects.all()
print(res)
# 查询名字叫xxx的书(是个列表:QuerySet)
res = models.Book.objects.filter(name='xxx')
res = models.Book.objects.filter(name='xxx')[0]
res = models.Book.objects.filter(name='xxx').first()
# 查询名字叫xxx的书(就是book对象),如果没有或者由多个,都报错
# 查询结果必须有且仅有一个才正常,否则报错
res=models.Book.objects.get(name='sss')
#
print(res.name)
return HttpResponse('两本书保存成功')