码迷,mamicode.com
首页 > 其他好文 > 详细

作业20

时间:2017-11-23 08:14:09      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:分享   text   ++   get   sql   ext   head   box   ping   

js:设置return

技术分享图片
function fnLogin() {
    var un = document.getElementById("username");
    var us = document.getElementById("password");
    var uE = document.getElementById("error_box")
    var isE = true;
    uE.innerHTML = "<br>";
    if (un.value.length < 6 || un.value.length > 20) {
        document.getElementById(‘error_box‘).innerHTML = "用户名必须在6-20个字符之间";
        isE = false;
        return isE;

    } else if ((un.value.charCodeAt(0) >= 48) && (un.value.charCodeAt(0) <= 57)) {
        uE.innerHTML = "用户名首字母不能为数字";
        isE = false;
        return isE;

    }
    else for (var i = 0; i < un.value.length; i++) {
            if (((un.value.charCodeAt(i) < 48) || (un.value.charCodeAt(i) > 57)) && ((un.value.charCodeAt(i) < 97) || (un.value.charCodeAt(i) > 122))) {
                uE.innerHTML = "用户名只能为数字或字母";
                isE = false;
                return isE;

            }

        }
    if (us.value.length < 6 || us.value.length > 20) {
        document.getElementById(‘error_box‘).innerHTML = "密码必须在6-20个字符之间";
        isE = false;
        return isE;
    }

    return isE;
}
技术分享图片

html:设置

  1. form
  2. input
技术分享图片
<!DOCTYPE html>
<html lang="en">
<head>
    {% extends ‘index.html‘ %}
    <meta charset="UTF-8">
    <title>
        {% block title %}
            登录页
        {% endblock %}</title>

    {% block head %}
        <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
        <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
        <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
        <script src="{{ url_for(‘static‘,filename=‘javascript/dl.js‘) }}"></script>

        <link rel="stylesheet" type="text/css" href="{{ url_for(‘static‘,filename=‘css/dl.css‘) }}">

    {% endblock %}

</head>
<body>
{% block body %}

    <form action="{{ url_for(‘login‘) }}" method="post">
        <div id="dljm" class="panel panel-info">
            <h2 class="deng" class="panel-title">登陆</h2>
            <div id="nr" class="panel-body">

                <div class="input_box">
                    Username:<input type="text" id="username" placeholder="请输入用户名" name="dlusername">
                </div>
                <br>
                <div class="input_box">
                    Password: <input type="password" id="password" placeholder="请输入密码" name="dlpassword">
                </div>
                <div class="error_box" id="error_box"><br></div>
                <div class="bt">

                    <button class="zhuce" onclick="fnLogin()">登录</button>
                </div>
                <br>
                <input type="radio" name="role" value="stu">学生
                <input type="radio" name="role" value="tea">教师<br>
                <input type="checkbox" value="true"><span>记住我</span><br><a
                    href="http://www.gzcc.cn/html/yonghufenglei/xuesheng/">登陆遇到问题</a><br>
            </div>

        </div>
    </form>
{% endblock %}

</body>
</html>
技术分享图片

py:

  1. @app.route设置methods
  2. GET
  3. POST
    1. 读取表单数据
    2. 查询数据库
      1. 用户名密码对:
        1. 记住用户名
        2. 跳转到首页
      2. 用户名密码不对:
        1. 提示相应错误。
技术分享图片
@app.route(‘/register/‘, methods=[‘GET‘, ‘POST‘])
def register():
    if request.method == ‘GET‘:
        return render_template(‘zhuce.html‘)
    else:
        username = request.form.get(‘username‘)
        password = request.form.get(‘password‘)
        nickname = request.form.get(‘nickname‘)
        userphone=request.form.get(‘userphone‘)
        user = User.query.filter(User.username == username).first()
        if user:
            return "账户已存在"
        else:
            user = User(username=username, password=password, nickname=nickname,userphone=userphone)
            db.session.add(user)
            db.session.commit()
            return redirect(url_for(‘login‘))
技术分享图片

session:

  1. 从`flask`中导入`session`
  2. 设置`SECRET_KEY`
  3. 操作字典一样操作`session`:增加用户名`session[‘username‘]=`username
技术分享图片
import os

DEBUG=True

SECRET_KEY=os.urandom(24) #加密key

DIALECT=‘myaql‘
DRIVER=‘mysqldb‘
USERNAME=‘root‘
PASSWORD=‘ROOT‘
HOST=‘127.0.0.1‘
PORT=‘3306‘
DATABASE=‘mis_db‘

作业20

标签:分享   text   ++   get   sql   ext   head   box   ping   

原文地址:http://www.cnblogs.com/z1-z/p/7881446.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!