![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
上节内容回顾: 1、Django请求生命周期 -> URL对应关系(匹配) -> 视图函数 -> 返回用户字符串 -> URL对应关系(匹配) -> 视图函数 -> 打开一个HTML文件,读取内容 2、创建django projcet django-admin startproject mysite .. mysite mysite - 配置文件 - url.py - settings.py cd mysite python manage.py startapp cmdb mysite mysite - 配置文件 - urls.py - settings.py cmdb - views.py - admin.py - models.py # 创建数据库表 3、配置 模板路径 静态文件路径 # CSRF 4、编写程序 a. url.py /index/ -> func b. views.py def func(request): # 包含所有的请求数据 ... ---业务处理 return HttpResponse('字符串') return render(request, 'index.html', {''}) retrun redirect('URL') c. 模板语言 return render(request, 'index.html', {'li': [11,22,33]}) {% for item in li %} <h1>{{item}}</h1> {% endfor %} *********** 索引用点 ********** <h2> {{item.0 }} </h2> 一、路由系统,URL 1、url(r'^index/', views.index), url(r'^home/', views.Home.as_view()), 2、url(r'^detail-(\d+).html', views.detail), 3、url(r'^detail-(?P<nid>\d+)-(?P<uid>\d+).html', views.detail) #推荐使用 PS: def detail(request, *args,**kwargs): pass 实战: a. url(r'^detail-(\d+)-(\d+).html', views.detail), def func(request, nid, uid): #id是内置函数,不要用 pass def func(request, *args): args = (2,9) def func(request, *args, **kwargs): args = (2,9) b. url(r'^detail-(?P<nid>\d+)-(?P<uid>\d+).html', views.detail) def func(request, nid, uid): pass def funct(request, **kwargs): kwargs = {'nid': 1, 'uid': 3} def func(request, *args, **kwargs): kwargs = {'nid': 1, 'uid': 3} 4、 name 对URL路由关系进行命名, ***** 以后可以根据此名称生成自己想要的URL ***** 在urls里 url(r'^asdfasdfasdf/', views.index, name='i1'), url(r'^yug/(\d+)/(\d+)/', views.index, name='i2'), url(r'^buy/(?P<pid>\d+)/(?P<nid>\d+)/', views.index, name='i3'), 在views里 def func(request, *args, **kwargs): from django.urls import reverse url1 = reverse('i1') # asdfasdfasdf/ url2 = reverse('i2', args=(1,2,)) # yug/1/2/ url3 = reverse('i3', kwargs={'pid': 1, "nid": 9}) # buy/1/9/ xxx.html(在模板语言里) {% url "i1" %} # asdfasdfasdf/ {% url "i2" 1 2 %} # yug/1/2/ #指定页面 {% url "i3" pid=1 nid=9 %} # buy/1/9/ 注: # 当前的URL request.path_info 5、多级路由 project/urls.py from django.conf.urls import url,include from django.contrib import admin urlpatterns = [ url(r'^cmdb/', include("app01.urls")), url(r'^monitor/', include("app02.urls")), ] app01/urls.py from django.conf.urls import url,include from django.contrib import admin from app01 import views urlpatterns = [ url(r'^login/', views.login), ] app02/urls.py from django.conf.urls import url,include from django.contrib import admin from app02 import views urlpatterns = [ url(r'^login/', views.login), ] 6、默认值(欠) 7、命名空间(欠) 二、视图 1、获取用户请求数据 request.GET request.POST request.FILES PS: GET:获取数据 POST:提交数据 2、checkbox等多选的内容 request.POST.getlist() 3、上传文件 # 上传文件,form标签做特殊设置 obj = request.FILES.get('fafafa') obj.name f = open(obj.name, mode='wb') for item in obj.chunks(): f.write(item) f.close() 4、FBV & CBV(class) function base view url.py index -> 函数名 view.py def 函数(request): ... ====》 /index/ -> 函数名 /index/ -> 类 ====》 建议:两者都用 5、装饰器 欠 三、模板 四、ORM操作 1、db first 先登录数据库写sql语句创建表结构,工具(如python)连接后自动在本地生成类, 以后不用写sql语句,根据类就能操作数据库 2、code first 先写代码(类),类再生成数据库表(主流都是code first 如sqlalchemy,Django等) select * from tb where id > 1 # 对应关系 models.tb.objects.filter(id__gt=1) models.tb.objects.filter(id=1) models.tb.objects.filter(id__lt=1) 创建类 a. 先写类 from django.db import models # app01_userinfo class UserInfo(models.Model): # id列,自增,主键 # 用户名列,字符串类型,指定长度 username = models.CharField(max_length=32) password = models.CharField(max_length=64) b. 在settings里注册APP INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'app01', ] c. 执行命令 python manage.py makemigrations python manage.py migrate d. ********** 注意 *********** Django默认使用MySQLdb模块链接MySQL 主动修改为pymysql,在project同名文件夹下的__init__文件中添加如下代码即可: import pymysql pymysql.install_as_MySQLdb() 1. 根据类自动创建数据库表 # app下的models.py python manage.py makemigrations python manage.py migrate 字段: 字符串类型 数字 时间 二进制 自增(primary_key=True) 字段的参数: null -> db是否可以为空 default -> 默认值 primary_key -> 主键 db_column -> 列名 db_index -> 索引 unique -> 唯一索引 unique_for_date -> unique_for_month unique_for_year auto_now -> 创建时,自动生成时间 auto_now_add -> 更新时,自动更新为当前时间 # obj = UserGroup.objects.filter(id=1).update(caption='CEO') # obj = UserGroup.objects.filter(id=1).first() # obj.caption = "CEO" # obj.save() choices -> django admin中显示下拉框,避免连表查询(因为效率低) blank -> django admin是否可以为空 verbose_name -> django admin显示字段中文 editable -> django admin是否可以被编辑 error_messages -> 错误信息欠 help_text -> django admin提示 validators -> django form ,自定义错误信息(欠) 创建 Django 用户:python manage.py createsuperuser 更多http://www.cnblogs.com/wupeiqi/articles/5246483.html 2. 根据类对数据库表中的数据进行各种操作 一对多: a. 外键 b. 外键字段_id c. models.tb.object.create(name='root', user_group_id=1) d. userlist = models.tb.object.all() for row in userlist: row.id row.user_group_id row.user_group.caption #跨表操作 =================== 作业:用户管理 ==================== 1、用户组的增删改查 2、用户增删改查 - 添加必须是模态对话框 - 删除必须是模态对话框 - 修改,必须显示默认值(可以用if-else判断) 3、比较好看的页面 4、预习: http://www.cnblogs.com/wupeiqi/articles/5246483.html
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 from django.contrib import admin 2 from app01 import models 3 # Register your models here. 4 admin.site.register(models.UserInfo)
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 from django.db import models 2 3 # Create your models here. 4 # app01_userinfo 默认生成的表名 5 class UserGroup(models.Model): 6 uid=models.AutoField(primary_key=True) #创建自增列 7 caption=models.CharField(max_length=32) 8 ctime=models.DateTimeField(auto_now_add=True,null=True) #Django自动创建这一列,不用自己写 9 uptime=models.DateTimeField(auto_now=True,null=True) 10 # obj=UserGroup.objects.filter(id=1).first().update(caption='CEO') #不生效 11 # obj=UserGroup.objects.filter(id=1).first() 12 # obj.caption='CEO' 13 # obj.save() 14 class UserInfo(models.Model): #必须继承models.Model 15 # id列,自增,主键 --Django默认自动隐含创建 16 # 用户名列,字符串类型,指定长度 17 #字符串、数字、时间、二进制 18 username = models.CharField(max_length=32,blank=True,verbose_name='用户名') 19 password = models.CharField(max_length=64,help_text='pwd') 20 email = models.EmailField(max_length=64,null=True) 21 url = models.URLField(max_length=64,null=True) 22 23 #Django 生成时会加上id,user_group_id 数字 24 user_group=models.ForeignKey("UserGroup",to_field="uid",default=1,on_delete=models.CASCADE) #to_field与哪个字段(主键)关联,默认也是主键 25 #(uid,caption,ctime,uptime) 26 27 user_type_choices=( 28 (1,'超级用户'), 29 (2,'普通用户'), 30 (3,'普普通用户'), 31 ) 32 user_type_id=models.IntegerField(choices=user_type_choices,default=1)
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 """s14day19_2 URL Configuration 2 3 The `urlpatterns` list routes URLs to views. For more information please see: 4 https://docs.djangoproject.com/en/1.10/topics/http/urls/ 5 Examples: 6 Function views 7 1. Add an import: from my_app import views 8 2. Add a URL to urlpatterns: url(r'^$', views.home, name='home') 9 Class-based views 10 1. Add an import: from other_app.views import Home 11 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') 12 Including another URLconf 13 1. Import the include() function: from django.conf.urls import url, include 14 2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) 15 """ 16 from django.conf.urls import url,include 17 from django.contrib import admin 18 from app01 import views 19 urlpatterns = [ 20 url(r'^login/', views.login), 21 url(r'^index/', views.index), 22 url(r'^user_info/', views.user_info), 23 url(r'^userdetail-(?P<nid>\d+)/', views.user_detail), 24 url(r'^userdel-(?P<nid>\d+)/', views.user_del), 25 url(r'^useredit-(?P<nid>\d+)/', views.user_edit), 26 url(r'^orm/', views.orm), 27 ]
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 from django.shortcuts import render,HttpResponse,redirect 2 # Create your views here. 3 # for i in USER_DICT.items() 4 # USER_DICT = { 5 # '1': {'name': 'root1', 'email': 'root@live.com'}, 6 # '2': {'name': 'root2', 'email': 'root@live.com'}, 7 # '3': {'name': 'root3', 'email': 'root@live.com'}, 8 # '4': {'name': 'root4', 'email': 'root@live.com'}, 9 # '5': {'name': 'root5', 'email': 'root@live.com'}, 10 # } 11 # USER_LIST = [ 12 # {'name': 'root'} 13 # {'name': 'root'} 14 # {'name': 'root'} 15 # ] 16 # 17 # {% for item in user_list%} 18 # 19 # USER_DICT = { 20 # 'k1': 'root1', 21 # 'k2': 'root2', 22 # 'k3': 'root3', 23 # 'k4': 'root4', 24 # } 25 USER_DICT = { 26 '1': {'name': 'root1', 'email': 'root@live.com'}, 27 '2': {'name': 'root2', 'email': 'root@live.com'}, 28 '3': {'name': 'root3', 'email': 'root@live.com'}, 29 '4': {'name': 'root4', 'email': 'root@live.com'}, 30 '5': {'name': 'root5', 'email': 'root@live.com'}, 31 } 32 def index(request,nid,uid): 33 # indexx 34 print(request.path_info) 35 # /asdfasdfasdf/13/ 36 from django.urls import reverse 37 # v = reverse('indexx',args=(90,88,)) 38 v = reverse('indexx',kwargs={"nid":1, 'uid': '99'}) 39 print(v) 40 return render(request, 'index.html', {'user_dict': USER_DICT}) 41 # def detail(request): 42 # nid = request.GET.get('nid') 43 # detail_info = USER_DICT[nid] 44 # return render(request, 'detail.html', {'detail_info': detail_info}) 45 46 # http://127.0.0.1:8000/detail-2-9.html 47 def detail(request,nid): 48 detail_info = USER_DICT[nid] 49 return render(request, 'detail.html', {'detail_info': detail_info}) 50 """ 51 def login(request): 52 if request.method == "GET": 53 return render(request, 'login.html') 54 elif request.method == "POST": 55 u = request.POST.get('user') 56 p = request.POST.get('pwd') 57 if u == 'alex' and p == '123': 58 return redirect('/index/') 59 else: 60 return render(request, 'login.html') 61 else: 62 # PUT,DELETE,HEAD,OPTION... 63 return redirect('/index/') 64 """ 65 def login(request): 66 if request.method == "GET": 67 return render(request, 'login.html') 68 elif request.method == "POST": 69 # radio 70 # v = request.POST.get('gender') 71 # print(v) 72 # v = request.POST.getlist('favor') 73 # print(v) 74 # v = request.POST.get('fafafa') 75 # print(v) 76 obj = request.FILES.get('fafafa') 77 print(obj,type(obj),obj.name) 78 import os 79 file_path = os.path.join('upload', obj.name) 80 f = open(file_path, mode="wb") 81 for i in obj.chunks(): 82 f.write(i) 83 f.close() 84 from django.core.files.uploadedfile import InMemoryUploadedFile 85 return render(request, 'login.html') 86 else: 87 # PUT,DELETE,HEAD,OPTION... 88 return redirect('/index/') 89 # def home(request): 90 # return HttpResponse('Home') 91 from django.views import View 92 class Home(View): 93 def dispatch(self, request, *args, **kwargs): 94 # 调用父类中的dispatch 95 print('before') 96 result = super(Home,self).dispatch(request, *args, **kwargs) 97 print('after') 98 return result 99 def get(self,request): 100 print(request.method) 101 return render(request, 'home.html') 102 def post(self,request): 103 print(request.method,'POST') 104 return render(request, 'home.html')
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 from django.shortcuts import render,HttpResponse,redirect 2 def login(request): 3 models.UserGroup.objects.create(caption='DBA') 4 if request.method == "GET": 5 return render(request, 'login.html') 6 elif request.method == "POST": 7 # 数据库中执行 select * from user where usernam='x' and password='x' 8 u = request.POST.get('user') 9 p = request.POST.get('pwd') 10 # obj = models.UserInfo.objects.filter(username=u,password=p).first() 11 # print(obj)# obj None,无用户 12 # count = models.UserInfo.objects.filter(username=u, password=p).count() #获取个数 13 obj = models.UserInfo.objects.filter(username=u, password=p).first() #推荐使用 14 if obj: 15 return redirect('/cmdb/index/') 16 else: 17 return render(request, 'login.html') 18 else: 19 # PUT,DELETE,HEAD,OPTION... 20 return redirect('/index/') 21 def index(request): 22 return render(request, 'index.html') 23 def user_info(request): 24 if request.method == "GET": 25 user_list = models.UserInfo.objects.all() 26 group_list=models.UserGroup.objects.all() 27 # for row in user_list: 28 # print(row.id) 29 # print(row.user_group.uid) 30 # print(row.user_group.caption) 31 # print(user_list.query) #查看sql语句 32 # QuerySet [obj(id,username,email,user_group_id,user_group(uid,caption...)),obj,] 33 return render(request, 'user_info.html', {'user_list': user_list,"group_list":group_list}) 34 elif request.method == 'POST': 35 u = request.POST.get('user') 36 p = request.POST.get('pwd') 37 models.UserInfo.objects.create(username=u,password=p) 38 return redirect('/cmdb/user_info/') 39 # user_list = models.UserInfo.objects.all() 40 # return render(request, 'user_info.html', {'user_list': user_list}) 41 def user_detail(request, nid): 42 obj = models.UserInfo.objects.filter(id=nid).first() 43 # models.UserInfo.objects.get(id=nid) # 取单条数据,如果不存在,直接报错 44 return render(request, 'user_detail.html', {'obj': obj}) 45 def user_del(request, nid): 46 models.UserInfo.objects.filter(id=nid).delete() 47 return redirect('/cmdb/user_info/') 48 def user_edit(request, nid): 49 if request.method == "GET": 50 obj = models.UserInfo.objects.filter(id=nid).first() 51 return render(request, 'user_edit.html',{'obj': obj}) 52 elif request.method == "POST": 53 nid = request.POST.get('id') 54 u = request.POST.get('username') 55 p = request.POST.get('password') 56 models.UserInfo.objects.filter(id=nid).update(username=u,password=p) 57 return redirect('/cmdb/user_info/') 58 from app01 import models 59 def orm(request): 60 # 创建1(1)(推荐) 61 # models.UserInfo.objects.create(username='root',password='123') 62 # 创建1(2) 63 # dic = {'username': 'eric', 'password': '666'} 64 # models.UserInfo.objects.create(**dic) 65 # 创建2 66 # obj = models.UserInfo(username='alex',password='123') 67 # obj.save() 68 # 查 69 # result = models.UserInfo.objects.all() 70 # result = models.UserInfo.objects.filter(username='root',password='123') #相当于where 71 # 72 # result,QuerySet类型 => Django提供的 => [] 理解成列表 73 # [obj(id,username,password),obj(id,username,password), obj(id,username,password)] 74 # for row in result: 75 # print(row.id,row.username,row.password) 76 # print(result) 77 # 删除 78 # models.UserInfo.objects.filter(username="alex").delete() 79 # 更新 80 # models.UserInfo.objects.filter(id=3).update(password="69") 81 #一对多 82 # user_list=models.UserInfo.objects.all() 83 models.UserInfo.objects.create( 84 username='root1', 85 password='123', 86 email='dasdad', 87 url='dsadsaf', 88 # user_group=models.UserGroup.objects.filter(id=1).first(), 89 user_group_id=1, 90 ) 91 return HttpResponse('orm') 92 # def home(request): 93 # return HttpResponse('Home') 94 from django.views import View 95 class Home(View): 96 def dispatch(self, request, *args, **kwargs): 97 # 调用父类中的dispatch 98 print('before') 99 result = super(Home,self).dispatch(request, *args, **kwargs) 100 print('after') 101 return result 102 def get(self,request): 103 print(request.method) 104 return render(request, 'home.html') 105 def post(self,request): 106 print(request.method,'POST') 107 return render(request, 'home.html')
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 import os 2 3 # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 4 BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 5 6 7 # Quick-start development settings - unsuitable for production 8 # See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ 9 10 # SECURITY WARNING: keep the secret key used in production secret! 11 SECRET_KEY = 'r=q!3-2o^_ei^^$wy6geroevs*p(!r14y7s3h8(op_w%051!y$' 12 13 # SECURITY WARNING: don't run with debug turned on in production! 14 DEBUG = True 15 16 ALLOWED_HOSTS = [] 17 18 # Application definition 19 INSTALLED_APPS = [ 20 'django.contrib.admin', 21 'django.contrib.auth', 22 'django.contrib.contenttypes', 23 'django.contrib.sessions', 24 'django.contrib.messages', 25 'django.contrib.staticfiles', 26 'app01', 27 ] 28 29 MIDDLEWARE = [ 30 'django.middleware.security.SecurityMiddleware', 31 'django.contrib.sessions.middleware.SessionMiddleware', 32 'django.middleware.common.CommonMiddleware', 33 #'django.middleware.csrf.CsrfViewMiddleware', 34 'django.contrib.auth.middleware.AuthenticationMiddleware', 35 'django.contrib.messages.middleware.MessageMiddleware', 36 'django.middleware.clickjacking.XFrameOptionsMiddleware', 37 ] 38 39 ROOT_URLCONF = 's14day19_2.urls' 40 41 TEMPLATES = [ 42 { 43 'BACKEND': 'django.template.backends.django.DjangoTemplates', 44 'DIRS': [os.path.join(BASE_DIR, 'templates')] 45 , 46 'APP_DIRS': True, 47 'OPTIONS': { 48 'context_processors': [ 49 'django.template.context_processors.debug', 50 'django.template.context_processors.request', 51 'django.contrib.auth.context_processors.auth', 52 'django.contrib.messages.context_processors.messages', 53 ], 54 }, 55 }, 56 ] 57 58 WSGI_APPLICATION = 's14day19_2.wsgi.application' 59 60 61 # Database 62 # https://docs.djangoproject.com/en/1.10/ref/settings/#databases 63 64 DATABASES = { 65 'default': { 66 'ENGINE': 'django.db.backends.sqlite3', 67 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 68 } 69 } 70 71 72 73 # Password validation 74 # https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators 75 76 AUTH_PASSWORD_VALIDATORS = [ 77 { 78 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 79 }, 80 { 81 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 82 }, 83 { 84 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 85 }, 86 { 87 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 88 }, 89 ] 90 91 92 # Internationalization 93 # https://docs.djangoproject.com/en/1.10/topics/i18n/ 94 95 LANGUAGE_CODE = 'en-us' 96 97 TIME_ZONE = 'UTC' 98 99 USE_I18N = True 100 101 USE_L10N = True 102 103 USE_TZ = True 104 105 106 # Static files (CSS, JavaScript, Images) 107 # https://docs.djangoproject.com/en/1.10/howto/static-files/ 108 109 STATIC_URL = '/static/' 110 STATICFILES_DIRS = ( 111 os.path.join(BASE_DIR, 'static'), 112 )
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 from django.conf.urls import url,include 2 from django.contrib import admin 3 urlpatterns = [ 4 url(r'^admin/', admin.site.urls), 5 url(r'^cmdb/', include("app01.urls")), 6 url(r'^monitor/', include("app02.urls")), 7 ] 8 """ 9 urlpatterns = [ 10 url(r'^admin/', admin.site.urls), 11 url(r'^asdfasdfasdf/(?P<nid>\d+)/(?P<uid>\d+)/', views.index, name='indexx'), 12 url(r'^login/', views.login), 13 # url(r'^home/', views.home), 14 url(r'^home/', views.Home.as_view()), 15 # url(r'^detail/', views.detail), 16 # url(r'^detail-(\d+)-(\d+).html', views.detail), #按照形式参数顺序 17 # url(r'^detail-(?P<nid>\d+)-(?P<uid>\d+).html', views.detail), #分组 18 url(r'^detail-(?P<nid>\d+).html', views.detail), 19 ] 20 """
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 import os 2 3 from django.core.wsgi import get_wsgi_application 4 5 os.environ.setdefault("DJANGO_SETTINGS_MODULE", "s14day19_2.settings") 6 7 application = get_wsgi_application()
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 </head> 7 <body> 8 <h1>详细信息</h1> 9 <h6>用户名:{{ detail_info.name }}</h6> 10 <h6>邮箱:{{ detail_info.email }}</h6> 11 </body> 12 </html>
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 </head> 7 <body> 8 <form action="/home/" method="POST"> 9 <input type="text" name="user"/> 10 <input type="submit" /> 11 </form> 12 </body> 13 </html>
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 <style> 7 body{ 8 margin: 0; 9 } 10 .menu{ 11 display: block; 12 padding: 5px; 13 } 14 </style> 15 </head> 16 <body> 17 <div style="height: 48px;background-color: black;color: white"> 18 张扬凌晨三点玩愤怒的小鸟 19 </div> 20 <div> 21 <div style="position: absolute;top:48px;bottom: 0;left: 0;width: 200px;background-color: brown;"> 22 <a class="menu" href="/cmdb/user_info/">用户管理</a> 23 <a class="menu" href="/cmdb/user_group/">用户组管理</a> 24 </div> 25 <div style="position:absolute;top:48px;left: 210px;bottom: 0;right: 0;overflow: auto"> 26 </div> 27 </div> 28 </body> 29 </html>
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 </head> 7 <body> 8 <form action="/login/" method="POST" enctype="multipart/form-data"> 9 <p> 10 <input type="text" name="user" placeholder="用户名" /> 11 </p> 12 <p> 13 <input type="password" name="pwd" placeholder="密码" /> 14 </p> 15 <p> 16 男:<input type="radio" name="gender" value="1"/> 17 女:<input type="radio" name="gender" value="2"/> 18 张扬:<input type="radio" name="gender" value="3"/> 19 </p> 20 <p> 21 男:<input type="checkbox" name="favor" value="11"/> 22 女:<input type="checkbox" name="favor" value="22"/> 23 张扬:<input type="checkbox" name="favor" value="33"/> 24 </p> 25 <p> 26 <select name="city" multiple> 27 <option value="sh">上海</option> 28 <option value="bj">北京</option> 29 <option value="tj">天津</option> 30 </select> 31 </p> 32 <p> 33 <input type="file" name="fafafa"/> 34 </p> 35 <input type="submit" value="提交"/> 36 </form> 37 </body> 38 </html>
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 </head> 7 <body> 8 <form action="/cmdb/login/" method="POST" enctype="multipart/form-data"> 9 <p> 10 <input type="text" name="user" placeholder="用户名" /> 11 </p> 12 <p> 13 <input type="password" name="pwd" placeholder="密码" /> 14 </p> 15 <input type="submit" value="提交"/> 16 </form> 17 </body> 18 </html>
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 <style> 7 body{ 8 margin: 0; 9 } 10 .menu{ 11 display: block; 12 padding: 5px; 13 } 14 </style> 15 </head> 16 <body> 17 <div style="height: 48px;background-color: black;color: white"> 18 张扬凌晨三点玩愤怒的小鸟 19 </div> 20 <div> 21 <div style="position: absolute;top:48px;bottom: 0;left: 0;width: 200px;background-color: brown;"> 22 <a class="menu" href="/cmdb/user_info/">用户管理</a> 23 <a class="menu" href="/cmdb/user_group/">用户组管理</a> 24 </div> 25 <div style="position:absolute;top:48px;left: 210px;bottom: 0;right: 0;overflow: auto"> 26 <h1>用户详细信息</h1> 27 <h5>{{ obj.id }}</h5> 28 <h5>{{ obj.name }}</h5> 29 <h5>{{ obj.password }}</h5> 30 </div> 31 </div> 32 </body> 33 </html>
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 <style> 7 body{ 8 margin: 0; 9 } 10 .menu{ 11 display: block; 12 padding: 5px; 13 } 14 </style> 15 </head> 16 <body> 17 <div style="height: 48px;background-color: black;color: white"> 18 张扬凌晨三点玩愤怒的小鸟 19 </div> 20 <div> 21 <div style="position: absolute;top:48px;bottom: 0;left: 0;width: 200px;background-color: brown;"> 22 <a class="menu" href="/cmdb/user_info/">用户管理</a> 23 <a class="menu" href="/cmdb/user_group/">用户组管理</a> 24 </div> 25 <div style="position:absolute;top:48px;left: 210px;bottom: 0;right: 0;overflow: auto"> 26 <h1>编辑用户</h1> 27 <form method="post" action="/cmdb/useredit-{{ obj.id }}/"> 28 <input style="display: none" type="text" name="id" value="{{ obj.id }}" /> 29 <input type="text" name="username" value="{{ obj.username }}" /> 30 <input type="text" name="password" value="{{ obj.password }}"/> 31 <input type="submit" value="提交" /> 32 </form> 33 </div> 34 </div> 35 </body> 36 </html>
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 <style> 7 body{ 8 margin: 0; 9 } 10 .menu{ 11 display: block; 12 padding: 5px; 13 } 14 </style> 15 </head> 16 <body> 17 <div style="height: 48px;background-color: black;color: white"> 18 张扬凌晨三点玩愤怒的小鸟 19 </div> 20 <div> 21 <div style="position: absolute;top:48px;bottom: 0;left: 0;width: 200px;background-color: brown;"> 22 <a class="menu" href="/cmdb/user_info/">用户管理</a> 23 <a class="menu" href="/cmdb/user_group/">用户组管理</a> 24 </div> 25 <div style="position:absolute;top:48px;left: 210px;bottom: 0;right: 0;overflow: auto"> 26 <h3>添加用户</h3> 27 <form method="POST" action="/cmdb/user_info/"> 28 <input type="text" name="user" /> 29 <input type="text" name="pwd" /> 30 <select name="group_id"> 31 {% for item in group_list %} 32 <option value="{{ item.uid }}">{{ item.caption }}</option> 33 {% endfor %} 34 </select> 35 <input type="submit" value="添加"/> 36 </form> 37 <h3>用户列表</h3> 38 <ul> 39 {% for row in user_list %} 40 <li> 41 <a href="/cmdb/userdetail-{{ row.id }}/">{{ row.username }}</a> | 42 <span>{{ row.user_group.caption }}</span> 43 <a href="/cmdb/userdel-{{ row.id }}/">删除</a> | 44 <a href="/cmdb/useredit-{{ row.id }}/">编辑</a> 45 </li> 46 {% endfor %} 47 </ul> 48 </div> 49 </div> 50 </body> 51 </html>