Django中的cookie与session
2016-03-16 15:22
399 查看
cookie与session的实现原理
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <style> .header{ height: 48px; } </style> </head> <body> <div class="header"> <div style="float: right">{{ username }}</div> <div style="float: right"><a href="/app01/logout/">注销</a></div> </div> <div style="height: 500px;background-color: #ddd"></div> </body> </html>
home.html
views.py
def login(request): if request.method == "POST": username = request.POST.get('username') pwd = request.POST.get('pwd') if username == 'alex' and pwd == '123': request.session['IS_LOGIN'] = True request.session['USRNAME'] = 'alex' return redirect('/app01/home/') elif username == 'eirc' and pwd == '123': request.session['IS_LOGIN'] = True request.session['USRNAME'] = 'eirc' return redirect('/app01/home/') return render(request, 'login.html') def home(request): is_login = request.session.get('IS_LOGIN', False) if is_login: username = request.session.get('USRNAME', False) return render(request, 'home.html', {'username': username}) else: return redirect("/app01/login/")
相关文章推荐
- la 4945 free goodies,不会!
- Django View基础
- Django~Excel,PDF
- Go语言核心之美 2.1-整数
- hdu 4775 Infinite Go(暴力)
- Golang 中的格式化输入输出
- Django--中间件
- [Canvas绘图] 第35节 藏图阁(15) AlphaGo与李世石的围棋大战之第五局
- django-debug-tool配置
- 机器学习系列(8)_读《Nature》论文,看AlphaGo养成
- mongo 从 collection 中随机查询多条记录
- AlphaGo关键技术,Deep Learning(深度学习)<1>
- 一张图解AlphaGo原理及弱点
- Google浏览器Chrome安装失败解决办法
- algorithm@ find the shortest path in a graph using BFS
- 蓝桥杯 ALGO-122(记忆化搜索)
- SENGO森果网招商
- HOTPOWER.【专注游戏界面外包】/接游戏界面外包/logo外包/icon
- Django入门(九) ajax异步请求
- google zxing生成二维码