• 一个初学者的辛酸路程-基于Django写BBS项目


    前言

    基于Django的学习

    详情

    登录界面

    找个模板
    右键,检查源码
     
     
    函数
     
    def login(request):
        errors = {}
        if request.method == "POST":
            username = request.POST.get("username")
            password = request.POST.get("password")
            user = authenticate(username=username,password=password)
            print("auth res",user)
            if user:
                print("authenticate success")
                return redirect("/")
            else:
                errors = {"error":"用户名或者密码错误"}
        return render(request,'login.html',errors)
     
    URL
    url(r'^login$', views.login,name="login"),
     
    HTML
    {% extends 'base.html' %}
     
    {% block body %}
        <div class="container">
            <div class="col-lg-3 col-lg-offset-4">
                <form class="form-signin" method="POST">
                    <h2 class="form-signin-heading">抽屉热门社区</h2>
                    <label for="inputEmail" class="sr-only">用户名</label>
                    <input type="text" name="username" id="inputEmail" class="form-control" placeholder="username" required autofocus>
                    <label for="inputPassword" class="sr-only">Password</label>
                    <input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required>
     
                    <span style="color: red;">{{ error }}</span>
                    <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">Sign in</button>
                </form>
            </div>
     
        </div>
    {% endblock %}
     
    URL
    1. url(r'^login$', views.login,name="login"),
     
    HTML
    1. {% extends 'base.html' %}
       
      {% block body %}
          <div class="container">
              <div class="col-lg-3 col-lg-offset-4">
                  <form class="form-signin" method="POST">
                      <h2 class="form-signin-heading">抽屉热门社区</h2>
                      <label for="inputEmail" class="sr-only">用户名</label>
                      <input type="text" name="username" id="inputEmail" class="form-control" placeholder="username" required autofocus>
                      <label for="inputPassword" class="sr-only">Password</label>
                      <input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required>
       
                      <span style="color: red;">{{ error }}</span>
                      <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">Sign in</button>
                  </form>
              </div>
       
          </div>
      {% endblock %}
     
    跳转
    1. def index(request):
          return redirect("/category/1/")
  • 相关阅读:
    一个前端的博客
    win10安装redis
    RabbitMQ的基本使用
    SpringMVC 中 @ControllerAdvice 注解的三种使用场景
    在Spring cloud中使用Spring Cloud Alibaba Nacos Discovery报错
    MSBUILD : error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。
    asp.net自定义错误信息处理
    MVC返回值详解
    C#集合
    C#linq查询方法使用简介
  • 原文地址:https://www.cnblogs.com/jixuege-1/p/6653935.html
Copyright © 2020-2023  润新知