Django项目003
【摘要】 项目用户登录
1、当用户在浏览器输入登录页面地址时项目的工作路径:
from django.conf.urls import url
from django.contrib import admin
from MiniApps import views
urlpatterns = [
url('admin/', admin.site.urls),
url('login/', views.login),
url('user_list/', views.userList),
]
2、进入登录函数
from django.shortcuts import HttpResponse, render, redirect
def login(request):
"""
用户登录函数
:param request:
:return:
"""
error_massage = ""
if request.method == 'POST':
print(request.POST["email"])
print(request.POST["pwd"])
email = request.POST.get("email", None)
password = request.POST.get("pwd", None)
if email == "***********@outlook.com" and password == "********":
return redirect("https://www.youtube.com/channel/UCGXsvcvFZt8IHeAtonvmGtg/playlists")
else:
error_massage = "邮箱或者密码错误!请重新登录!"
return render(request, "login.html", {"error": error_massage})
3、展示的登录页面
<form class="form-horizontal" action="/login/" method="post">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label"></label>
<div class="input-group col-sm-8">
<span class="input-group-addon"><i class="fa fa-envelope-o fa-fw"></i></span>
<input type="email" name="email" class="form-control" id="inputEmail3" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-2 control-label"></label>
<div class="input-group col-sm-8">
<span class="input-group-addon"><i class="fa fa-key fa-fw"></i></span>
<input type="password" name="pwd" class="form-control" id="inputPassword3" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="input-group col-sm-offset-2 col-sm-8">
<div class="checkbox">
<label>
<input type="checkbox"> 记住我
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="input-group col-sm-offset-2 col-sm-8">
<button type="submit" class="btn btn-primary btn-block">登录</button>
</div>
</div>
<p class="text-danger text-center">{{ error }}</p>
</form>
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)