Django-实现简易员工操作
Published in:2020-08-23 |

Django实现用户登陆,注册,以及session会话强制登陆,以及对员工的信息的增加,删除,修改操作

Django实现简易的员工操作

Django实现用户登陆,注册,以及session会话强制登陆,以及对员工的信息的增加,删除,修改操作

结构

model模型

创建APP,挂载APP,创建用户表和员工表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
from django.db import models

# Create your models here.
class User(models.Model):
username = models.CharField(max_length=20)
name =models.CharField(max_length=20,default=None,null=True)
userpwd = models.CharField(max_length=20)
sex = models.CharField(max_length=20)

class Staff(models.Model):
name = models.CharField(max_length=20)
salary = models.IntegerField()
age = models.IntegerField()

执行python manage.py makemigrations ,以及 python manage migrations

views.py视图

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from django.http import HttpResponse
from django.shortcuts import render, redirect
from work.models import User, Staff

# 主页面
def emplist(request):
# 判断是否存在session,不存在强制返回登陆界面
res = request.session.get('is_login')
if res:
return redirect("work:emplist_logic") # 存在session,返回员工页面
return redirect('work:login') # 不存在session,强制返回为登陆页面

# 登陆页面
def login(request):
# 判断密码是否正确,正确设置session为True
username = request.POST.get('name')
userpwd = request.POST.get('pwd')
res = User.objects.filter(username=username, userpwd=userpwd)
if res:
request.session['is_login'] = True # 密码正确,设置session
return redirect("work:emplist") # 重定向到员工页面
else:
return render(request, "work/login.html") # 密码错误.返回登陆页面重新登陆

# 注册页面
def regist(request):
return render(request, "work/regist.html")
# 添加员工页面
def addEmp(request):
return render(request, "work/addEmp.html")
# 修改员工页面
def updateEmp(request):
# 填写获取的该员工信息
id = request.GET.get('id')
staff = Staff.objects.get(pk=id)
return render(request, "work/updateEmp.html", {"staff": staff})

# 登陆逻辑
def login_logic(request):
username = request.POST.get("name")
userpwd = request.POST.get("pwd")
res = User.objects.filter(username=username, userpwd=userpwd)
if res:
request.session['is_login'] = True # 登陆正确设置及session会话
return redirect("work:emplist") # 重定向到员工页面
return render(request, "work/login.html") # 密码错误,返回登陆页面重新登陆

# 注册逻辑
def regist_logic(request):
username = request.POST.get("username")
name = request.POST.get("name")
userpwd = request.POST.get("pwd")
sex = request.POST.get("sex")
res = User.objects.filter(username=username) # 获取数据库是否拥有用户名
if res:
return HttpResponse("用户已存在")
User.objects.create(username=username, name=name, userpwd=userpwd, sex=sex)
return redirect("work:login")

# 添加员工逻辑
def addEmp_logic(request):
name = request.POST.get('name')
salary = request.POST.get('salary')
age = request.POST.get('age')
Staff.objects.create(name=name, salary=salary, age=age)
return redirect("work:emplist_logic")

# 修改数据逻辑
def updateEmp_logic(request):
# 根据修改页面的该员工的id
id = request.GET.get('id')
print(id)
staff = Staff.objects.get(pk=id)
# 获取到提交的修改数据
name = request.POST.get('name')
salary = request.POST.get('salary')
age = request.POST.get('age')
# 进行员工的信息修改
staff.name = name
staff.salary = salary
staff.age = age
staff.save()
return redirect("work:emplist")

# 删除员工
def delete_logic(request):
id = request.GET.get('id')
staff = Staff.objects.filter(pk=id)
staff.delete()
return redirect('work:emplist')

# 主页逻辑
def emplist_logic(request):
staff = Staff.objects.all()
print(len(staff))
return render(request, 'work/emplist.html', {"staff": staff})

urls.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# _*_coding:UTF-8 _*_
from django.urls import path,
from work import views

app_name = "work" #app名称
urlpatterns = [
path('emplist/', views.emplist,name="emplist"),
path('login/', views.login,name="login"),
path('regist/', views.regist,name="regist"),
path('login_logic/', views.login_logic,name="login_logic"),
path('regist_logic/', views.regist_logic,name="regist_logic"),
path('addemp/', views.addEmp,name="addemp"),
path('updateemp/', views.updateEmp,name="updateemp"),
path('addemp_logic/', views.addEmp_logic,name="addemp_logic"),
path('updateemp_logic/', views.updateEmp_logic,name="updateemp_logic"),
path('delete_logic/', views.delete_logic,name="delete_logic"),
path('emplist_logic/', views.emplist_logic,name="emplist_logic"),

]

static静态样式

css

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
body
{
margin: 0;
font-size: 62.5%;
font-family: Verdana, Arial, Helvetica, sans-serif;
padding: 15px 0;
background: #eeeeee;
}

#wrap {
width: 820px;
margin: 0 auto;
background: url(../img/all/bg.gif) top repeat-y #FFFFFF;
}

#top_content {
padding: 0 10px;
}

#topheader {
padding: 25px 15px 15px 15px;
margin: 0 auto 0 auto;
background: url(../img/all/top_left.gif) top left repeat-x #85C329;
}

#rightheader {
float: right;
width: 375px;
height: 40px;
color: #FFFFFF;
text-align: right;
}
#rightheader p {
padding: 35px 15px 0 0;
margin: 0;
text-align: right;
}
#rightheader p span {
font-weight: bold;
}
#rightheader a:link, #rightheader a:visited {
color: #FFFFFF;
text-decoration: underline;
}

#title {
padding: 0;
margin: 0;
font-size: 2.5em;
color: #FFFFFF;
}
#title span {
font-size: 0.5em;
font-style: italic;
}
#title a:link, #title a:visited {
color: #FFFFFF;
text-decoration: none;
}
#title a:hover {
color: #E1F3C7;
}

#navigation {
background: #74A8F5;
border-top: 1px solid #ffffff;
height: 25px;
clear: both
}
#navigation ul {
padding: 0;
margin: 0;
list-style: none;
font-size: 1.1em;
height: 25px;
}
#navigation ul li {
display: inline;
}
#navigation ul li a {
color: #FFFFFF;
display: block;
text-decoration: none;
float: left;
line-height: 25px;
padding: 0 16px;
border-right: 1px solid #ffffff;
}
#navigation ul li a:hover {
background: #5494F3;
}

#content {
padding: 0 15px;
margin: 0 auto 0 auto;
background: url(../img/all/content_bg.gif) repeat-x left top #ffffff;
color: #666666;
}

#content p#whereami {
padding: 20px 0 15px 0;
margin: 0;
}
#whereami a:link, #whereami a:visited {
color: #73A822;
text-decoration: underline;
}

#content h1, #content h2,
#content h3, #content h4 , #content h5 {
color: #74A8F5;
}
#content h1 {
font-family: "Trebuchet MS", Arial, Helvetica;
padding: 0;
margin: 0 0 15px 0;
font-size: 2em;
}
#content h2 {
font-family: "Trebuchet MS", Arial, Helvetica;
padding: 0;
margin: 0 0 15px 0;
font-size: 1.5em;
}

#top_body, #content_body {
padding: 0 25px;
}

#footer {
background: url(../img/all/footer.gif) no-repeat center bottom ;
color: #FFFFFF;
padding: 0 10px 13px 10px;
}
#footer p {
padding: 0;
margin: 0;
}
#footer p a:link, #footer p a:visited {
color: #FFFFFF;
font-style: italic;
text-decoration: none;
}
#footer #footer_bg {
background: url(../img/all/footer_bg.gif) repeat-x left bottom #85C329;
padding: 15px 15px 25px 15px;
border-top: 1px solid #7BB425;
}

#footer #design {
display: block;
width: 150px;
height: 30px;
float: right;
line-height: 20px;
padding: 0 5px;
text-align: right;
color: #E1F3C7;
}
#footer #design a {
color: #FFFFFF;
text-decoration: underline;
}

.table {
margin-bottom: 15px;
width: 100%;
border-collapse: collapse;
}
.table_header td {
background: url(../img/all/tableheader-bg.gif) no-repeat left top;
padding: 5px 10px;
color: rgb(70,122,167);
border-top: 1px solid #CBD6DE;
border-bottom: 1px solid #ADBECB;
font-size: 1.1em;
font-weight: bold;
}
.table_header td a:link, .table_header td a:visited {
text-decoration: underline;
color: rgb(70,122,167);
}
.table_header td a:hover {
text-decoration: underline;
color: #73A822;
}
.table_header td {
border: 1px solid #CBD6DE;
}

.row1 td, .row2 td, .row_hover td, .paging_row td {
padding: 5px 10px;
color: #666666;
border: 1px solid #CBD6DE;
}
.row1 td {
background: #ffffff;
}
.row2 td {
background: #eeeeee;
}
.row_hover td {
background: #FBFACE;
color: #000000;
}

.hidden {
display: none;
}

.little {
font-size: 10px;
}

.clear {
clear: both;
}

.img_left {
float: left;
padding: 1px;
border: 1px solid #cccccc;
margin: 0 10px 10px 0;
width: 110px;
height:150px;
}

/* #content ul basic style for unordered lists
------------------------------------------------*/
#content ul {
font-size: 1.1em;
line-height: 1.8em;
margin: 0 0 15px 0;
padding: 0;
list-style-type: none;
}

/* #content p paragraphs
-----------------------------*/
#content p {
font-size: 1.2em;
margin: 0;
padding: 0 0 15px 0;
}

/* #content p a links in paragraphs
------------------------------------*/
#content p a:link, #content p a:visited,
.table a:link, .table a:visited,
.link a {
color: #73A822;
text-decoration: none;
}
#content p a:hover, .table a:hover, .link a:hover {
text-decoration: underline;
}

/* #content ul.green (73A822)
--------------------------------*/
#content ul.green li {
padding: 0 0 0 20px;
margin: 0;
background: url(../img/all/bullet_green.gif) no-repeat 1px 3px;
font-size: 1.1em;
}
#content ul.green li a:link, #content ul.green li a:visited {
color: #73A822;
text-decoration: none;
}
#content ul.green li a:hover {
color: #73A822;
text-decoration: underline;
}

/* #content ul.black (73A822)
--------------------------------*/
#content ul.black li {
padding: 0 0 0 20px;
margin: 0;
background: url(../img/all/bullet_grey.gif) no-repeat 1px 3px;
font-size: 1.1em;
}
#content ul.black li a:link, #content ul.black li a:visited {
color: #666666;
text-decoration: none;
}
#content ul.black li a:hover {
color: #999999;
text-decoration: underline;
}

/* #content ol
--------------------------------*/
#content ol {
padding: 0 0 0 25px;
margin: 0 0 15px 0;
line-height: 1.8em;
}

#content ol li {
font-size: 1.1em;
}
#content ol li a:link, #content ol li a:visited {
color: #73A822;
text-decoration: none;
}
#content ol li a:hover {
color: #73A822;
text-decoration: underline;
}

/* #content p.paging
---------------------------------*/
#content p.paging {
padding: 5px;
border: 1px solid #CBD6DE;
text-align: center;
margin-bottom: 15px;
background: #eeeeee;
}

/* .small_input smaller text in inputs/combos
-----------------------------------------------*/
.small_input {
font-size: 10px;
}

/* .form_table style for table used in forms
---------------------------------------------*/
.form_table {
margin-bottom: 15px;
font-size: 1.1em;
}
.form_table p {
margin: 0;
padding: 0;
}
.form_table td {
padding: 5px 10px;
}

/* .checkbox_nomargins clear all margins from a checkbox
---------------------------------------------------------*/
.checkbox_nomargins {
/*margin:0;width:13px;height:13px;overflow:hidden;
font-size: 10px;*/
margin: 0;
padding: 0;
}

/* .button some buttons style - inspired from wordpress
------------------------------*/
input.button {
margin: 0;
padding: 2px;
border: 3px double #999999;
border-left-color: #ccc;
border-top-color: #ccc;
background: url(../img/all/button.gif) repeat-x left top;
font-size: 11px;
font-family: Verdana, Arial, Helvetica, sans-serif;
}

/* form style for forms
-------------------------*/
form {
padding: 0;
margin: 0;
}

/* input.inputgri - some style for inputs
--------------------------------------------*/
input.inputgri, select.inputgri, textarea.inputgri {
background: #eeeeee;
font-size: 14px;
border: 1px solid #cccccc;
padding: 3px;
}
input.inputgri:focus, select.inputgri:focus , textarea.inputgri:focus {
background: #ffffff;
border: 1px solid #686868;
}

/* .notice - messages to user
--------------------------------*/
.notice {
background: #CAEA99;
border: 1px solid #70A522;
padding: 15px 15px 15px 15px;
margin-bottom: 15px;
font-size: 1.2em;
color: #333333;
}
.notice_error {
background: #FEDCDA;
border: 1px solid #CE090E;
padding: 15px 15px 15px 15px;
margin-bottom: 15px;
font-size: 1.2em;
color: #333333;
}
#notice a {
color: #333333;
text-decoration: underline;
}

/* Other links
----------------*/
.other_links {
background: #eeeeee;
border-top: 1px solid #cccccc;
padding: 5px;
margin: 0 0 15px 0;
}
#content .other_links h2 {
color: #999999;
padding: 0 0 0 3px;
margin: 0;
}
#content .other_links ul {
padding: 0;
margin: 0;
}
#content .other_links ul li {
padding: 0 0 0 20px;
background: url(../img/all/bullet_grey.gif) no-repeat left center;
}
#content .other_links a, #content .other_links a:visited {
color: #999999;
text-decoration: underline;
}
#content .other_links a:hover {
color: #666666;
}

/* code */
code {
font-size: 1.2em;
color: #73A822;
}

HTML

emplist.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>emplist</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="/static/work/css/style.css" />
</head>
<body>
<div id="wrap">
<div id="top_content">
<div id="header">
<div id="rightheader">
<p>
2009/11/20
<br />
</p>
</div>
<div id="topheader">
<h1 id="title">
<a href="#">main</a>
</h1>
</div>
<div id="navigation">
</div>
</div>
<div id="content">
<p id="whereami">
</p>
<h1>
Welcome!
</h1>
<table class="table">
<tr class="table_header">
<td>
ID
</td>
<td>
Name
</td>
<td>
Salary
</td>
<td>
Age
</td>
<td>
Operation
</td>
</tr>
{% for i in staff %}
{% if forloop.counter|divisibleby:2 %}
<tr class="row1" style="background-color: #ffffff">
<td>
{{ forloop.counter }}
</td>
<td>
{{ i.name }}
</td>
<td>
{{ i.salary }}
</td>
<td>
{{ i.age }}
</td>
<td>
<a href="{% url "work:delete_logic" %}?id={{ i.id }}">delete emp</a>&nbsp;<a href="{% url "work:updateemp" %}?id={{ i.id }}">update emp</a>
</td>
</tr>
{% else %}
<tr class="row2" style="background-color: #eeeeee">
<td>
{{ forloop.counter }}
</td>
<td>
{{ i.name }}
</td>
<td>
{{ i.salary }}
</td>
<td>
{{ i.age }}
</td>
<td>
<a href="{% url "work:delete_logic" %}?id={{ i.id }}">delete emp</a>&nbsp;<a href="{% url "work:updateemp" %}?id={{ i.id }}">update emp</a>
</td>
</tr>
{% endif %}
{% endfor %}

</table>
<p>
<input type="button" class="button" value="Add Employee" onclick="location='{% url "work:addemp" %}'"/>
</p>




</div>
</div>
<div id="footer">
<div id="footer_bg">
ABC@126.com
</div>
</div>
</div>
</body>
</html>

login.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>login</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css"
href="/static/work/css/style.css" />
</head>

<body>
<div id="wrap">
<div id="top_content">
<div id="header">
<div id="rightheader">
<p>
2009/11/20
<br />
</p>
</div>
<div id="topheader">
<h1 id="title">
<a href="#">main</a>
</h1>
</div>
<div id="navigation">
</div>
</div>
<div id="content">
<p id="whereami">
</p>
<h1>
login
</h1>
<form action="{% url "work:login_logic" %}" method="post">
{% csrf_token %}
<table cellpadding="0" cellspacing="0" border="0"
class="form_table">
<tr>
<td valign="middle" align="right">
username:
</td>
<td valign="middle" align="left">
<input type="text" class="inputgri" name="name" />
</td>
</tr>
<tr>
<td valign="middle" align="right">
password:
</td>
<td valign="middle" align="left">
<input type="password" class="inputgri" name="pwd" />
</td>
</tr>
</table>
<p>
<input type="submit" class="button" value="Submit &raquo;" />
</p>
</form>
</div>
</div>
<div id="footer">
<div id="footer_bg">
ABC@126.com
</div>
</div>
</div>
</body>
</html>

register.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>regist</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="/static/work/css/style.css" />
</head>
<body>
<div id="wrap">
<div id="top_content">
<div id="header">
<div id="rightheader">
<p>
2009/11/20
<br />
</p>
</div>
<div id="topheader">
<h1 id="title">
<a href="#">main</a>
</h1>
</div>
<div id="navigation">
</div>
</div>
<div id="content">
<p id="whereami">
</p>
<h1>
注册
</h1>
<form action="{% url "work:regist_logic" %}" method="post">
{% csrf_token %}
<table cellpadding="0" cellspacing="0" border="0"
class="form_table">
<tr>
<td valign="middle" align="right">
用户名:
</td>
<td valign="middle" align="left">
<input type="text" class="inputgri" name="username" />
</td>
</tr>
<tr>
<td valign="middle" align="right">
真实姓名:
</td>
<td valign="middle" align="left">
<input type="text" class="inputgri" name="name" />
</td>
</tr>
<tr>
<td valign="middle" align="right">
密码:
</td>
<td valign="middle" align="left">
<input type="password" class="inputgri" name="pwd" />
</td>
</tr>
<tr>
<td valign="middle" align="right">
性别:
</td>
<td valign="middle" align="left">

<input type="radio" class="inputgri" name="sex" value="m" checked="checked"/>

<input type="radio" class="inputgri" name="sex" value="f"/>
</td>
</tr>

<tr>
{# <td valign="middle" align="right">#}
{# 验证码:#}
{# <img id="num" src="image" />#}
{# <a href="javascript:;" onclick="document.getElementById('num').src = 'image?'+(new Date()).getTime()">换一张</a>#}
{# </td>#}
<td valign="middle" align="left">
<input type="text" class="inputgri" name="number" />
</td>
</tr>
</table>
<p>
<input type="submit" class="button" value="Submit &raquo;" />
</p>
</form>
</div>
</div>
<div id="footer">
<div id="footer_bg">
ABC@126.com
</div>
</div>
</div>
</body>
</html>

updateEmp.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>update Emp</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css"
href="/static/work/css/style.css" />
</head>

<body>
<div id="wrap">
<div id="top_content">
<div id="header">
<div id="rightheader">
<p>
2009/11/20
<br />
</p>
</div>
<div id="topheader">
<h1 id="title">
<a href="#">Main</a>
</h1>
</div>
<div id="navigation">
</div>
</div>
<div id="content">
<p id="whereami">
</p>
<h1>
update Emp info:
</h1>
<form action="{% url "work:updateemp_logic" %}?id={{ staff.id }}" method="post">
{% csrf_token %}
<table cellpadding="0" cellspacing="0" border="0"
class="form_table">
<tr>
<td valign="middle" align="right">
id:
</td>
<td valign="middle" align="left" >
{{ staff.id}}
</td>
</tr>
<tr>
<td valign="middle" align="right">
name:
</td>
<td valign="middle" align="left">
<input type="text" class="inputgri" name="name" value="{{ staff.name }}"/>
</td>
</tr>
<tr>
<td valign="middle" align="right">
salary:
</td>
<td valign="middle" align="left">
<input type="text" class="inputgri" name="salary" value="{{ staff.salary }}"/>
</td>
</tr>
<tr>
<td valign="middle" align="right">
age:
</td>
<td valign="middle" align="left">
<input type="text" class="inputgri" name="age" value="{{ staff.age }}"/>
</td>
</tr>
</table>
<p>
<input type="submit" class="button" value="Confirm" />
</p>
</form>
</div>
</div>
<div id="footer">
<div id="footer_bg">
ABC@126.com
</div>
</div>
</div>
</body>
</html>

addEmp.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>add Emp</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css"
href="/static/work/css/style.css" />
</head>

<body>
<div id="wrap">
<div id="top_content">
<div id="header">
<div id="rightheader">
<p>
2009/11/20
<br />
</p>
</div>
<div id="topheader">
<h1 id="title">
<a href="#">Main</a>
</h1>
</div>
<div id="navigation">
</div>
</div>
<div id="content">
<p id="whereami">
</p>
<h1>
add Emp info:
</h1>
<form action="{% url "work:addemp_logic" %}" method="post">
{% csrf_token %}
<table cellpadding="0" cellspacing="0" border="0"
class="form_table">
<tr>
<td valign="middle" align="right">
name:
</td>
<td valign="middle" align="left">
<input type="text" class="inputgri" name="name" />
</td>
</tr>
<tr>
<td valign="middle" align="right">
salary:
</td>
<td valign="middle" align="left">
<input type="text" class="inputgri" name="salary" />
</td>
</tr>
<tr>
<td valign="middle" align="right">
age:
</td>
<td valign="middle" align="left">
<input type="text" class="inputgri" name="age" />
</td>
</tr>
</table>
<p>
<input type="submit" class="button" value="Confirm" />
</p>
</form>
</div>
</div>
<div id="footer">
<div id="footer_bg">
ABC@126.com
</div>
</div>
</div>
</body>
</html>

Prev:
Django-员工操作
Next:
jQuery-实现简易购物车