Django分页+增删改查 演示
源码下载地址:https://download.csdn.net/download/qq_35622606/87719248
其他小笔记:
django-admin.exe startproject mysite
python .\manage.py startapp app01
python manage.py makemigrations
python manage.py migrate
python manage.py runserver
安装 mysqlclient
pip install mysqlclient==1.4.1
或者mysqlclient wheel
控制台运行命令安装:
pip install wheel mysqlclient-1.4.6-cp36-cp36m-win_amd64.whl
https://www.lfd.uci.edu/~gohlke/pythonlibs/#
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME':'test', 'USER': 'root', 'PASSWORD': 'root', 'HOST': '127.0.0.1', 'PORT': '3307', } }Django基本的增删改查:
def depart(request): # ORM操作 # 新增 #models.Department.objects.create(title="销售部",count=10) #models.Department.objects.create(**{"title":"销售部","count":0}) #查询 #queryset=models.Department.objects.all() #queryset=models.Department.objects.filter(id__gt=1)#id>1 # for obj in queryset: # print(obj.id,obj.title,obj.count) #obj=models.Department.objects.filter(id=1).first() #print(obj.id,obj.title,obj.count) #删除 #models.Department.objects.filter(id=1).delete() #更新 models.Department.objects.filter(id=2).update(count=100) return HttpResponse("执行成功")