zoukankan      html  css  js  c++  java
  • 登录功能的实现:

    views:

    from django.shortcuts import render,HttpResponse,redirect

    # Create your views here.

    def index(request):
    print(request.path_info)
    return HttpResponse('<h1>index</h1>')
    # return render(request, 'index.html')

    def modal(request):
    return render(request, 'modal.html')

    def login(request):
    # 判断如果是get请求返回登录页面:
    if request.method == "GET":
    return render(request,"login.html")
    # 否则处理post请求、获取提交数据:
    else:
    print(request.POST)
    #获取用户名:
    username = request.POST.get("user")
    password = request.POST.get("password")
    #用户名和密码校验:
    if username == "alex" and password == "alexdsb":
    #登录成功:
    return redirect("/index/")
    else:
    return render(request,"login.html",{"error":"用户名或密码错误"})
    login.html:
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Title</title>
    {# 增加bootstrap样式:#}
    <link rel="stylesheet" href="/static/plugins/bootstrap-3.3.7-dist/css/bootstrap.min.css">
    {# 导入css文件:#}
    <link rel="stylesheet" href="/static/css/signin.css">
    </head>
    <body>

    <div class="container">
    {# novalidate定义不校验、更改post请求、action提交到哪个地址#}
    <form class="form-signin" method="post" action="" novalidate>
    <h2 class="form-signin-heading">Please sign in</h2>
    <label for="inputEmail" class="sr-only">用户名</label>
    {# required定义必填、autofocus自动聚焦、name属性#}
    <input type="text" id="inputEmail" class="form-control" name="user" placeholder="输入用户名" required="" autofocus="">
    <label for="inputPassword" class="sr-only">密码</label>
    <input type="password" id="inputPassword" class="form-control" name="password" placeholder="输入密码" required="">
    {# 提示错误字典的key:#}
    <div>{{ error }}</div>
    <div class="checkbox">
    <label>
    <input type="checkbox" value="remember-me"> Remember me
    </label>
    </div>
    <button class="btn btn-lg btn-primary btn-block" type="submit">登录</button>
    {# 定义提交:#}
    {# <input type="submit" value="登录">#}
    </form>

    </div> <!-- /container -->


    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>


    </body>
    </html>
  • 相关阅读:
    opencv 1.0 与 2.0的库对应表
    OpenCV SIFT原理与源码分析
    计算机杂志排名
    opencv Installation in Linux and hello world
    SSL 通信及 java keystore 工具介绍
    侧方位停车技巧图解 教你快速便捷停车(图)
    opencv 中文文档地址
    books
    Mysql processlist命令
    MYSQL优化之碎片整理
  • 原文地址:https://www.cnblogs.com/zhang-da/p/12031639.html
Copyright © 2011-2022 走看看