工程下的urls.py中增加如下:from cmdb import views as cmdb #要把你要操作的项目import进来urlpatterns = [ url(r'orm', cmdb.orm) #增加这行]--------------------------------------------------------项目下的views.py中增加:from cmdb import models # 先将项目里的models加载进来def orm(request):# create # 1 way best use. #models.UserInfo.objects.create(username='xiaojianzheng',password='123') # 2 way ''' dict = {'username':'ciki','password':'123'} models.UserInfo.objects.create(**dict) ''' # 3 way ''' obj = models.UserInfo(username='lss',password='123') obj.save() '''# select # select all data use all() ''' result = models.UserInfo.objects.all() for x in result: print(x.id,x.username,x.password) #result, QuerySet => Django => [] #< QuerySet[ < UserInfo: UserInfo object >, < UserInfo: UserInfo object >, < UserInfo: UserInfo object > '''# delete #models.UserInfo.objects.filter(id=3).delete()# update #models.UserInfo.objects.filter(id=5).update(username='lss',password='456') result = models.UserInfo.objects.all() for x in result: print(x.id, x.username, x.password) return HttpResponse('ORM opration success.')