💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
![](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() ```