django简单用户登陆验证
django简单用户登陆验证
一.django简单用户登陆验证 前端页面:
from django.contrib.auth import authenticateuser = authenticate(username='john', password='secret')if user is not None: # the password verified for the user if user.is_active: print("User is valid, active and authenticated") else: print("The password is valid, but the account has been disabled!")else: # the authentication system was unable to verify the username and password print("The username and password were incorrect.") 来源:http://python.usyiyi.cn/django/intro/tutorial02.html
首页中登录/退出按钮
{% if request.user.is_authenticated %}
{% if request.user.is_authenticated %}