用户登录逻辑
发布日期:2021-06-29 04:55:55 浏览次数:2 分类:技术文章

本文共 876 字,大约阅读时间需要 2 分钟。

关于登录这个问题,登录界面同样是用form表单,用户输入用户名和密码,点击登录按钮提交form表单,我们通过我们设置的函数获取用户输入的数据,然后拿用户的用户名到数据库里进行匹配,如果匹配不到值说明用户名不存在,我们就在前端页面告知用户,如果匹配到值了则说明用户名存在,我们可以进一步验证密码,如果密码正确则跳转页面到内容页,如果密码错误则在前端页面告知用户。

def login(request):    if request.method == "POST" and request.POST:        name = request.POST.get("name")        password = request.POST.get("password")        user = User_one.objects.filter(userName=name)        if user:            if user[0].password == getPassword(password):                return HttpResponseRedirect("/student/page_student_list/1/")            else:                key = "密码错误"        else:            key = "用户名不存在"    return render(request,"login.html", locals())

在这里插入图片描述以下是加密函数,用于对密码进行加密

import hashlib      #导入hashlib包def getPassword(password):    md5 = hashlib.md5()    md5.update(password.encode())    result = md5.hexdigest()    return result

当然我们后续还要在里面加入cookie,这里暂时没有加入

转载地址:https://blog.csdn.net/Zhang_Chao_1998/article/details/86099727 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:基于django的异步请求总结
下一篇:Django cookie

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2024年04月09日 01时48分36秒