1,首先需要将本地数据库的表同步到django的models.py文件

py manage.py inspectdb tb_books tb_heros > demo001/models.py 

2,同步成功后models.py会根据每张表映射出不同的类

models.py文件根据数据库表映射出对应的类

3,然后根据不同的类执行增删改查实现数据库表的增删改查

在views.py中实现增删改查操作:
增:

from models import TbBooksdef add_info(request):tb = TbBooks()tb.btitle = '啦啦啦',tb.bpub_data = '1999-10-10',tb.bread = '100',tb.bcomment = '100'tb.save()

删:

from models import TbBooksdef del_info(request):tb = TbBooks.objects.filter(name='天龙八部').delete()

改:

from models import TbBooksdef modify_info(request):tb = TbBooks.objects.filter(name='笑傲江湖').update(is_delete=1)

查:

def find_info(request):tb = TbBooks.objects.filter(name='天龙八部')