Django用户登陆以及跳转后台管理页面3

Django用户登陆以及跳转后台管理页面1
http://www.cnblogs.com/ujq3/p/7891774.html

Django用户登陆以及跳转后台管理页面2
http://www.cnblogs.com/ujq3/p/7891901.html


 from django.shortcuts import render
# Create your views here. from django.shortcuts import render
from django.shortcuts import redirect #重新定向模块 def login(request):
#包含用户提交的所有信息
#获取用户提交方法
#print(request.method)
error_msg = ""
if request.method == "POST":
#获取用户通过POST提交过来的数据
user =request.POST.get('user',None)
pwd =request.POST.get('pwd',None)
if user == 'root' and pwd == '':
#去跳转到
return redirect('home.html')
else:
#用户密码不匹配
error_msg = '用户名或密码错误'
# user = request.POST['user']
# pwd = request.POST['pwd']
# print(user,pwd)
return render(request,'login.html',{'error_msg':error_msg}) USER_LIST =[
{'username': 'alex', 'email': 'alex@163.com', 'gender': '男'},
{'username': '黄逗', 'email': 'huandou@126.com', 'gender': '男'},
{'username': '小玉123', 'email': 'xiaoyu@139.com', 'gender': '女'},
] def home(request):
if request.method == "POST":
#获取用户添加的数据 POST请求中
u = request.POST.get('username')
e = request.POST.get('email')
g = request.POST.get('gender')
temp = {'username':u, 'email':e, 'gender':g}
USER_LIST.append(temp)
return render(request,'home.html',{'user_list':USER_LIST})

views.py

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<meta charset = "utf-8">
<title>Title</title>
<body style="margin: 0">
<div style="height: 48px;background-color: #ddb796"></div>
<div>
<form action="/home"method="post">
<input type="text" name="username" placeholder="用户名"/>
<input type="text" name="email" placeholder="邮箱"/>
<input type="text" name="gender" placeholder="性别"/>
<input type="submit" value="添加" />
</form>
</div>
<div>
<table>
{% for row in user_list %}
<tr>
<td>{{ row.username }}</td>
<td>{{ row.email }}</td>
<td>{{ row.gender }}</td>
</tr>
{% endfor %}
</table>
</div> </body>
</html>

home.html

Django用户登陆以及跳转后台管理页面3

上一篇:使用TS Session Broker实现终端服务负载均衡


下一篇:java变量命名规则