我想手动验证用户身份如何在项目的所有应用程序中保持用户登录?这是我的登录视图功能:
def sign(request):
context = {}
if request.method == 'POST':
form = SigninForm(data = request.POST)
if form.is_valid:
username = request.POST['username']
password = hashlib.sha256(request.POST['password'].encode('utf-8')).hexdigest()
users = customer.objects.all()
for user in users:
if username == user.username:
if password == user.password:
context['tmp'] = "OK"
Django具有内置的身份验证系统。在User authentication in Django中了解有关此内容的更多信息。
但是,您可以自定义它或完全重写它(使用您自己的逻辑)。在Customizing authentication in Django中了解有关此内容的更多信息。