python学习笔记_week19
上节内容回顾:
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
from django.contrib import admin
from app01 import models
# Register your models here.
admin.site.register(models.UserInfo)
from django.db import models # Create your models here.
# app01_userinfo 默认生成的表名
class UserGroup(models.Model):
uid=models.AutoField(primary_key=True) #创建自增列
caption=models.CharField(max_length=32)
ctime=models.DateTimeField(auto_now_add=True,null=True) #Django自动创建这一列,不用自己写
uptime=models.DateTimeField(auto_now=True,null=True)
# obj=UserGroup.objects.filter(id=1).first().update(caption='CEO') #不生效
# obj=UserGroup.objects.filter(id=1).first()
# obj.caption='CEO'
# obj.save()
class UserInfo(models.Model): #必须继承models.Model
# id列,自增,主键 --Django默认自动隐含创建
# 用户名列,字符串类型,指定长度
#字符串、数字、时间、二进制
username = models.CharField(max_length=32,blank=True,verbose_name='用户名')
password = models.CharField(max_length=64,help_text='pwd')
email = models.EmailField(max_length=64,null=True)
url = models.URLField(max_length=64,null=True) #Django 生成时会加上id,user_group_id 数字
user_group=models.ForeignKey("UserGroup",to_field="uid",default=1,on_delete=models.CASCADE) #to_field与哪个字段(主键)关联,默认也是主键
#(uid,caption,ctime,uptime) user_type_choices=(
(1,'超级用户'),
(2,'普通用户'),
(3,'普普通用户'),
)
user_type_id=models.IntegerField(choices=user_type_choices,default=1)
"""s14day19_2 URL Configuration The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/1.10/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url,include
from django.contrib import admin
from app01 import views
urlpatterns = [
url(r'^login/', views.login),
url(r'^index/', views.index),
url(r'^user_info/', views.user_info),
url(r'^userdetail-(?P<nid>\d+)/', views.user_detail),
url(r'^userdel-(?P<nid>\d+)/', views.user_del),
url(r'^useredit-(?P<nid>\d+)/', views.user_edit),
url(r'^orm/', views.orm),
]
from django.shortcuts import render,HttpResponse,redirect
# Create your views here.
# for i in USER_DICT.items()
# USER_DICT = {
# '1': {'name': 'root1', 'email': 'root@live.com'},
# '2': {'name': 'root2', 'email': 'root@live.com'},
# '3': {'name': 'root3', 'email': 'root@live.com'},
# '4': {'name': 'root4', 'email': 'root@live.com'},
# '5': {'name': 'root5', 'email': 'root@live.com'},
# }
# USER_LIST = [
# {'name': 'root'}
# {'name': 'root'}
# {'name': 'root'}
# ]
#
# {% for item in user_list%}
#
# USER_DICT = {
# 'k1': 'root1',
# 'k2': 'root2',
# 'k3': 'root3',
# 'k4': 'root4',
# }
USER_DICT = {
'': {'name': 'root1', 'email': 'root@live.com'},
'': {'name': 'root2', 'email': 'root@live.com'},
'': {'name': 'root3', 'email': 'root@live.com'},
'': {'name': 'root4', 'email': 'root@live.com'},
'': {'name': 'root5', 'email': 'root@live.com'},
}
def index(request,nid,uid):
# indexx
print(request.path_info)
# /asdfasdfasdf/13/
from django.urls import reverse
# v = reverse('indexx',args=(90,88,))
v = reverse('indexx',kwargs={"nid":1, 'uid': ''})
print(v)
return render(request, 'index.html', {'user_dict': USER_DICT})
# def detail(request):
# nid = request.GET.get('nid')
# detail_info = USER_DICT[nid]
# return render(request, 'detail.html', {'detail_info': detail_info}) # http://127.0.0.1:8000/detail-2-9.html
def detail(request,nid):
detail_info = USER_DICT[nid]
return render(request, 'detail.html', {'detail_info': detail_info})
"""
def login(request):
if request.method == "GET":
return render(request, 'login.html')
elif request.method == "POST":
u = request.POST.get('user')
p = request.POST.get('pwd')
if u == 'alex' and p == '123':
return redirect('/index/')
else:
return render(request, 'login.html')
else:
# PUT,DELETE,HEAD,OPTION...
return redirect('/index/')
"""
def login(request):
if request.method == "GET":
return render(request, 'login.html')
elif request.method == "POST":
# radio
# v = request.POST.get('gender')
# print(v)
# v = request.POST.getlist('favor')
# print(v)
# v = request.POST.get('fafafa')
# print(v)
obj = request.FILES.get('fafafa')
print(obj,type(obj),obj.name)
import os
file_path = os.path.join('upload', obj.name)
f = open(file_path, mode="wb")
for i in obj.chunks():
f.write(i)
f.close()
from django.core.files.uploadedfile import InMemoryUploadedFile
return render(request, 'login.html')
else:
# PUT,DELETE,HEAD,OPTION...
return redirect('/index/')
# def home(request):
# return HttpResponse('Home')
from django.views import View
class Home(View):
def dispatch(self, request, *args, **kwargs):
# 调用父类中的dispatch
print('before')
result = super(Home,self).dispatch(request, *args, **kwargs)
print('after')
return result
def get(self,request):
print(request.method)
return render(request, 'home.html')
def post(self,request):
print(request.method,'POST')
return render(request, 'home.html')
from django.shortcuts import render,HttpResponse,redirect
def login(request):
models.UserGroup.objects.create(caption='DBA')
if request.method == "GET":
return render(request, 'login.html')
elif request.method == "POST":
# 数据库中执行 select * from user where usernam='x' and password='x'
u = request.POST.get('user')
p = request.POST.get('pwd')
# obj = models.UserInfo.objects.filter(username=u,password=p).first()
# print(obj)# obj None,无用户
# count = models.UserInfo.objects.filter(username=u, password=p).count() #获取个数
obj = models.UserInfo.objects.filter(username=u, password=p).first() #推荐使用
if obj:
return redirect('/cmdb/index/')
else:
return render(request, 'login.html')
else:
# PUT,DELETE,HEAD,OPTION...
return redirect('/index/')
def index(request):
return render(request, 'index.html')
def user_info(request):
if request.method == "GET":
user_list = models.UserInfo.objects.all()
group_list=models.UserGroup.objects.all()
# for row in user_list:
# print(row.id)
# print(row.user_group.uid)
# print(row.user_group.caption)
# print(user_list.query) #查看sql语句
# QuerySet [obj(id,username,email,user_group_id,user_group(uid,caption...)),obj,]
return render(request, 'user_info.html', {'user_list': user_list,"group_list":group_list})
elif request.method == 'POST':
u = request.POST.get('user')
p = request.POST.get('pwd')
models.UserInfo.objects.create(username=u,password=p)
return redirect('/cmdb/user_info/')
# user_list = models.UserInfo.objects.all()
# return render(request, 'user_info.html', {'user_list': user_list})
def user_detail(request, nid):
obj = models.UserInfo.objects.filter(id=nid).first()
# models.UserInfo.objects.get(id=nid) # 取单条数据,如果不存在,直接报错
return render(request, 'user_detail.html', {'obj': obj})
def user_del(request, nid):
models.UserInfo.objects.filter(id=nid).delete()
return redirect('/cmdb/user_info/')
def user_edit(request, nid):
if request.method == "GET":
obj = models.UserInfo.objects.filter(id=nid).first()
return render(request, 'user_edit.html',{'obj': obj})
elif request.method == "POST":
nid = request.POST.get('id')
u = request.POST.get('username')
p = request.POST.get('password')
models.UserInfo.objects.filter(id=nid).update(username=u,password=p)
return redirect('/cmdb/user_info/')
from app01 import models
def orm(request):
# 创建1(1)(推荐)
# models.UserInfo.objects.create(username='root',password='123')
# 创建1(2)
# dic = {'username': 'eric', 'password': '666'}
# models.UserInfo.objects.create(**dic)
# 创建2
# obj = models.UserInfo(username='alex',password='123')
# obj.save()
# 查
# result = models.UserInfo.objects.all()
# result = models.UserInfo.objects.filter(username='root',password='123') #相当于where
#
# result,QuerySet类型 => Django提供的 => [] 理解成列表
# [obj(id,username,password),obj(id,username,password), obj(id,username,password)]
# for row in result:
# print(row.id,row.username,row.password)
# print(result)
# 删除
# models.UserInfo.objects.filter(username="alex").delete()
# 更新
# models.UserInfo.objects.filter(id=3).update(password="69")
#一对多
# user_list=models.UserInfo.objects.all()
models.UserInfo.objects.create(
username='root1',
password='',
email='dasdad',
url='dsadsaf',
# user_group=models.UserGroup.objects.filter(id=1).first(),
user_group_id=1,
)
return HttpResponse('orm')
# def home(request):
# return HttpResponse('Home')
from django.views import View
class Home(View):
def dispatch(self, request, *args, **kwargs):
# 调用父类中的dispatch
print('before')
result = super(Home,self).dispatch(request, *args, **kwargs)
print('after')
return result
def get(self,request):
print(request.method)
return render(request, 'home.html')
def post(self,request):
print(request.method,'POST')
return render(request, 'home.html')
import os # Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'r=q!3-2o^_ei^^$wy6geroevs*p(!r14y7s3h8(op_w%051!y$' # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True ALLOWED_HOSTS = [] # Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'app01',
] MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
#'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
] ROOT_URLCONF = 's14day19_2.urls' TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')]
,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
] WSGI_APPLICATION = 's14day19_2.wsgi.application' # Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
} # Password validation
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
] # Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/ LANGUAGE_CODE = 'en-us' TIME_ZONE = 'UTC' USE_I18N = True USE_L10N = True USE_TZ = True # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/ STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
from django.conf.urls import url,include
from django.contrib import admin
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^cmdb/', include("app01.urls")),
url(r'^monitor/', include("app02.urls")),
]
"""
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^asdfasdfasdf/(?P<nid>\d+)/(?P<uid>\d+)/', views.index, name='indexx'),
url(r'^login/', views.login),
# url(r'^home/', views.home),
url(r'^home/', views.Home.as_view()),
# url(r'^detail/', views.detail),
# url(r'^detail-(\d+)-(\d+).html', views.detail), #按照形式参数顺序
# url(r'^detail-(?P<nid>\d+)-(?P<uid>\d+).html', views.detail), #分组
url(r'^detail-(?P<nid>\d+).html', views.detail),
]
"""
import os from django.core.wsgi import get_wsgi_application os.environ.setdefault("DJANGO_SETTINGS_MODULE", "s14day19_2.settings") application = get_wsgi_application()
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>详细信息</h1>
<h6>用户名:{{ detail_info.name }}</h6>
<h6>邮箱:{{ detail_info.email }}</h6>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="/home/" method="POST">
<input type="text" name="user"/>
<input type="submit" />
</form>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body{
margin: 0;
}
.menu{
display: block;
padding: 5px;
}
</style>
</head>
<body>
<div style="height: 48px;background-color: black;color: white">
张扬凌晨三点玩愤怒的小鸟
</div>
<div>
<div style="position: absolute;top:48px;bottom: 0;left: 0;width: 200px;background-color: brown;">
<a class="menu" href="/cmdb/user_info/">用户管理</a>
<a class="menu" href="/cmdb/user_group/">用户组管理</a>
</div>
<div style="position:absolute;top:48px;left: 210px;bottom: 0;right: 0;overflow: auto">
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="/login/" method="POST" enctype="multipart/form-data">
<p>
<input type="text" name="user" placeholder="用户名" />
</p>
<p>
<input type="password" name="pwd" placeholder="密码" />
</p>
<p>
男:<input type="radio" name="gender" value="1"/>
女:<input type="radio" name="gender" value="2"/>
张扬:<input type="radio" name="gender" value="3"/>
</p>
<p>
男:<input type="checkbox" name="favor" value="11"/>
女:<input type="checkbox" name="favor" value="22"/>
张扬:<input type="checkbox" name="favor" value="33"/>
</p>
<p>
<select name="city" multiple>
<option value="sh">上海</option>
<option value="bj">北京</option>
<option value="tj">天津</option>
</select>
</p>
<p>
<input type="file" name="fafafa"/>
</p>
<input type="submit" value="提交"/>
</form>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="/cmdb/login/" method="POST" enctype="multipart/form-data">
<p>
<input type="text" name="user" placeholder="用户名" />
</p>
<p>
<input type="password" name="pwd" placeholder="密码" />
</p>
<input type="submit" value="提交"/>
</form>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body{
margin: 0;
}
.menu{
display: block;
padding: 5px;
}
</style>
</head>
<body>
<div style="height: 48px;background-color: black;color: white">
张扬凌晨三点玩愤怒的小鸟
</div>
<div>
<div style="position: absolute;top:48px;bottom: 0;left: 0;width: 200px;background-color: brown;">
<a class="menu" href="/cmdb/user_info/">用户管理</a>
<a class="menu" href="/cmdb/user_group/">用户组管理</a>
</div>
<div style="position:absolute;top:48px;left: 210px;bottom: 0;right: 0;overflow: auto">
<h1>用户详细信息</h1>
<h5>{{ obj.id }}</h5>
<h5>{{ obj.name }}</h5>
<h5>{{ obj.password }}</h5>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body{
margin: 0;
}
.menu{
display: block;
padding: 5px;
}
</style>
</head>
<body>
<div style="height: 48px;background-color: black;color: white">
张扬凌晨三点玩愤怒的小鸟
</div>
<div>
<div style="position: absolute;top:48px;bottom: 0;left: 0;width: 200px;background-color: brown;">
<a class="menu" href="/cmdb/user_info/">用户管理</a>
<a class="menu" href="/cmdb/user_group/">用户组管理</a>
</div>
<div style="position:absolute;top:48px;left: 210px;bottom: 0;right: 0;overflow: auto">
<h1>编辑用户</h1>
<form method="post" action="/cmdb/useredit-{{ obj.id }}/">
<input style="display: none" type="text" name="id" value="{{ obj.id }}" />
<input type="text" name="username" value="{{ obj.username }}" />
<input type="text" name="password" value="{{ obj.password }}"/>
<input type="submit" value="提交" />
</form>
</div>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
body{
margin: 0;
}
.menu{
display: block;
padding: 5px;
}
</style>
</head>
<body>
<div style="height: 48px;background-color: black;color: white">
张扬凌晨三点玩愤怒的小鸟
</div>
<div>
<div style="position: absolute;top:48px;bottom: 0;left: 0;width: 200px;background-color: brown;">
<a class="menu" href="/cmdb/user_info/">用户管理</a>
<a class="menu" href="/cmdb/user_group/">用户组管理</a>
</div>
<div style="position:absolute;top:48px;left: 210px;bottom: 0;right: 0;overflow: auto">
<h3>添加用户</h3>
<form method="POST" action="/cmdb/user_info/">
<input type="text" name="user" />
<input type="text" name="pwd" />
<select name="group_id">
{% for item in group_list %}
<option value="{{ item.uid }}">{{ item.caption }}</option>
{% endfor %}
</select>
<input type="submit" value="添加"/>
</form>
<h3>用户列表</h3>
<ul>
{% for row in user_list %}
<li>
<a href="/cmdb/userdetail-{{ row.id }}/">{{ row.username }}</a> |
<span>{{ row.user_group.caption }}</span>
<a href="/cmdb/userdel-{{ row.id }}/">删除</a> |
<a href="/cmdb/useredit-{{ row.id }}/">编辑</a>
</li>
{% endfor %}
</ul>
</div>
</div>
</body>
</html>
python学习笔记_week19的更多相关文章
- python学习笔记整理——字典
python学习笔记整理 数据结构--字典 无序的 {键:值} 对集合 用于查询的方法 len(d) Return the number of items in the dictionary d. 返 ...
- VS2013中Python学习笔记[Django Web的第一个网页]
前言 前面我简单介绍了Python的Hello World.看到有人问我搞搞Python的Web,一时兴起,就来试试看. 第一篇 VS2013中Python学习笔记[环境搭建] 简单介绍Python环 ...
- python学习笔记之module && package
个人总结: import module,module就是文件名,导入那个python文件 import package,package就是一个文件夹,导入的文件夹下有一个__init__.py的文件, ...
- python学习笔记(六)文件夹遍历,异常处理
python学习笔记(六) 文件夹遍历 1.递归遍历 import os allfile = [] def dirList(path): filelist = os.listdir(path) for ...
- python学习笔记--Django入门四 管理站点--二
接上一节 python学习笔记--Django入门四 管理站点 设置字段可选 编辑Book模块在email字段上加上blank=True,指定email字段为可选,代码如下: class Autho ...
- python学习笔记--Django入门0 安装dangjo
经过这几天的折腾,经历了Django的各种报错,翻译的内容虽然不错,但是与实际的版本有差别,会出现各种奇葩的错误.现在终于找到了解决方法:查看英文原版内容:http://djangobook.com/ ...
- python学习笔记(一)元组,序列,字典
python学习笔记(一)元组,序列,字典
- Pythoner | 你像从前一样的Python学习笔记
Pythoner | 你像从前一样的Python学习笔记 Pythoner
- OpenCV之Python学习笔记
OpenCV之Python学习笔记 直都在用Python+OpenCV做一些算法的原型.本来想留下发布一些文章的,可是整理一下就有点无奈了,都是写零散不成系统的小片段.现在看 到一本国外的新书< ...
随机推荐
- dubbo-admin在jdk8下不兼容
参考这里 修改pom.xml webx的依赖改为3..6版 <dependency> <groupId>com.alibaba.citrus</groupId> & ...
- Django--django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE
Django序列化时遇到错误: django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESP ...
- Unity单例
引自:http://www.unitymanual.com/thread-16916-1-1.html
- 阿里云ECS安装flannel启动问题
在阿里云ECS安装flannel,安装过程可以在网上找文章,这样的文章很多.我这里讲一下启动flannel遇到的两个问题的解决方法. 1,network.go:102] failed to retri ...
- java安装1.8和1.7,报错:Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVers
进入:C:\ProgramData\Oracle\Java\javapath; 删除:java.exe.javaw.exe.javaws.exe 删除:path的C:\ProgramData\Orac ...
- Java NIO系列教程(二) Channel通道介绍及FileChannel详解
目录: <Java NIO系列教程(二) Channel> <Java NIO系列教程(三) Channel之Socket通道> Channel是一个通道,可以通过它读取和写入 ...
- JAVA虚拟机关闭钩子(Shutdown Hook)
程序经常也会遇到进程挂掉的情况,一些状态没有正确的保存下来,这时候就需要在JVM关掉的时候执行一些清理现场的代码.JAVA中的ShutdownHook提供了比较好的方案. JDK提供了Java.Run ...
- 廖雪峰Java5集合-3Map-1使用Map
廖雪峰的视频不全,以下是疯狂Java关于Map的讲解 1.Map定义 Map是一种键值映射表,可以通过key快速查找value,同python的dict.key不允许重复,value可以重复. Map ...
- 使用SHOW binlog events查看binlog内容
用mysqlbinlog命令行查看binlog,觉得比较麻烦,突然发现原来mysql有个命令可以直接查看. SHOW BINLOG EVENTS [IN 'log_name'] [FROM pos] ...
- python的68个内置函数
内置函数 内置函数就是python给你提供的, 拿来直接用的函数, 比如print., input等. 截止到python版本3.6.2 python一共提供了68个内置函数. #68个内置函数 # ...