django authentication
django authentication
django session expiry
login and logout view.py
from django.contrib.auth import authenticate, login, logout
from django.shortcuts import render
def user_login(request):
if request.method == "POST":
# try:
# m = models.UserProfile.objects.get(email=request.POST['username'])
# except Exception:
# print("username doesn't exist")
# return render(request, "login.html")
username = request.POST["username"]
password = request.POST["password"]
print(username, password)
user = authenticate(request, email=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
# request.session.set_expiry(1800)
return render(request, "index1.html")
else:
return render(request, "login.html")
else:
return render(request, "login.html")
def user_logout(request):
logout(request)
return render(request, "login.html")
# try:
# del request.session['member_id']
# except KeyError:
# pass
login index.html
<form method="post" class="m-t" role="form" action="{% url 'login' %}">
{% csrf_token %}
<div class="form-group">
<input placeholder="Username" name="username">
</div>
<div class="form-group">
<input placeholder="Password" name="password">
</div>
<input type="submit" value="login" >
<input type="hidden" name="next" value="{{ next }}" />
<p><a href="{% url 'password_reset' %}">Lost password?</a></p>
</form>
logout.html
<a href="{% url 'logout' %}">
<i class="fa fa-sign-out">注销</i>
</a>
urls.py
urlpatterns = [
url(r'^login/', views.user_login, name="login"),
url(r'^logout/', views.user_logout, name="logout"),
]
django authentication的更多相关文章
- Django Authentication 用户认证系统
一. Django的认证系统 Django自带一个用户认证系统,用于处理用户账户.群组.许可和基于cookie的用户会话. 1.1 概览 Django的认证系统包含了身份验证和权限管理两部分.简单地说 ...
- Django authentication 使用方法
转自 : https://docs.djangoproject.com/en/1.8/topics/auth/customizing/
- Authentication of Django
Django Authentication 用户认证系统 一. Django的认证系统 Django自带一个用户认证系统,用于处理用户账户.群组.许可和基于cookie的用户会话. 1.1 概览 Dj ...
- Django自定义用户认证系统Customizing authentication
扩展已有的用户模型Extending the existing User model 有两种方法来扩展默认的User Model而不用重写自己的模型.如果你不需要改变存储在数据库中的字段,而只是需要改 ...
- User authentication in Django(用户认证)
一,概述: auth 系统包括: 1)Users 2)Permissions: Binary (yes/no) flags designating whether a user may perform ...
- Django admin定制化,User字段扩展[原创]
前言 参考上篇博文,我们利用了OneToOneField的方式使用了django自带的user,http://www.cnblogs.com/caseast/p/5909248.html , 但这么用 ...
- Redis+Django(Session,Cookie)的用户系统
一.Django authentication django authentication提供了一个便利的user api接口,无论在py中 request.user,参见Request and re ...
- Django 设置cookies与获取cookies.
在Django里面,使用Cookie和Session看起来好像是一样的,使用的方式都是request.COOKIES[XXX]和request.session[XXX],其中XXX是您想要取得的东西的 ...
- Redis+Django(Session,Cookie、Cache)的用户系统
转自 http://www.cnblogs.com/BeginMan/p/3890761.html 一.Django authentication django authentication 提供了一 ...
随机推荐
- Tomcat黑窗口改变Title
start cmd /K " && call startup.bat && pause && exit " 设置Title之后,再手 ...
- C++笔试题(七)
微软研究院是一个听起来就牛B的地方啊,反正我是进不去,不过不妨碍我看看他的笔试题到底是怎么样的.下面四道题就是微软研究院的笔试题目,题后附有我的解答.微软研究院(亚洲)的网址是:http://rese ...
- Django学习:url路由系统
一.MTV模型 1.Django的MTV分别代表: Model(模型):和数据库相关的,负责业务对象与数据库的对象(ORM) Template(模板):放所有的html文件 模板语法:目的是将白变量( ...
- first-child和last-child选择器 nth-child(n)第几个元素 nth-last-child(n)倒数第几个元素
:first-child 和 :last-child 分别表示父元素中第一个 或者 最后一个 子元素设置样式,如上图
- websocket实现群聊
server # @File: 群聊 from flask import Flask, render_template, request from geventwebsocket.handler im ...
- tcp聊天交互
#****setver端 import socket sk = socket.socket() adress = ('127.0.0.1', 8032) sk.bind(adress) sk.list ...
- IDEA远程调试hadoop程序
远程调试Hadoop各组件 Hadoop学习之配置Eclipse远程调试Hadoop IDEA远程调试hadoop Hadoop 研发之远程调试详细剖析--WordCount V2.0 eclipse ...
- Poj 3666 Making the Grade (排序+dp)
题目链接: Poj 3666 Making the Grade 题目描述: 给出一组数,每个数代表当前位置的地面高度,问把路径修成非递增或者非递减,需要花费的最小代价? 解题思路: 对于修好的路径的每 ...
- npm install error: MSBUILD : error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”
When I tried to run angular 4 material2 demo on my windows server 2012, got a error message: node-pr ...
- HDU 1221 Rectangle and Circle 考虑很多情况,good题
http://acm.hdu.edu.cn/showproblem.php?pid=1221 114 92 31 95 13 96 3 这题只需要判断圆和矩形是否相交,然后在里面是不算相交的. 那么就 ...