多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
![](https://img.kancloud.cn/41/e0/41e066af9a6c25a24868d9667253ec98_1241x333.jpg) ## ORM的增删改查 ### 添加数据 ``` views.py -------------------------------------------------------------------- from django.shortcuts import render from django.db import connection from .models import Book from django.http import HttpResponse def add_book(request): book = Book(name="Python",author="JR",price=78) book.save() return HttpResponse("书籍添加成功") ``` ### 查询数据 ``` 1.根据主键进行查找 book = Book.objects.get(pk=1) print(book) 2.根据其他条件来查找 book = Book.objects.filter(name="Python") print(book) 3.查询所有 book = Book.objects.all() ``` ### 删除数据 ``` book = Book.objects.get(pk=1) book.delete() ``` ### 修改数据 ``` book = Book.objects.get(pk=2) book.price = 200 book.save() ```