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

完成注册功能

时间:2017-11-21 14:49:13      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:rip   获取   url   else   ace   i++   eth   用户名   pass   

  1. js文件: onclick函数return True时才提交表单,return False时不提交表单。
  2. html文件:
    1. <form>中设置 action和method="post"
    2. <input> 中设置 name
  3. 主py文件中:
    1. from flask import  request, redirect, url_for
    2. @app.route(‘/regist/‘, methods=[‘GET‘, ‘POST’])

def regist():

   if request.method == ‘GET‘:

        return render_template(‘regist.html‘)

   else:

        username = request.form.get(‘username’)#获取form中的数据

        判断用户名是否存在:存在报错

  不存在,存到数据库中

       redirect重定向到登录页

function fnEnroll() {
    var zcoUname = document.getElementById("zcuname")
    var zcoError = document.getElementById("zcerror_box")
    var zcoUword1 = document.getElementById("zcuword1")
    var zcoUword2 = document.getElementById("zcuword2")
 
    zcoError.innerHTML = "<br>"
    if (zcoUname.value.length < 6 || zcoUname.value.length > 12) {
        zcoError.innerHTML = "用户名为6到12位";
        return
    } else if( (zcoUname.value.charCodeAt(0) >= 48) && (zcoUname.value.charCodeAt(0) <= 57)){
        zcoError.innerHTML = "用户名首位不能是数字";
        return
    } else for (var i = 0; i < zcoUname.value.length; i++) {
        if ((zcoUname.value.charCodeAt(i) < 48) || (zcoUname.value.charCodeAt(i) > 57) && (zcoUname.value.charCodeAt(i) < 97) || (zcoUname.value.charCodeAt(i) > 122)) {
            zcoError.innerHTML = "用户名只能是字母与数字";
            return
        }
    }
 
    if ((zcoUword1.value.length < 6) || (zcoUword1.value.length > 20)) {
        zcoError.innerHTML = "密码为6到20位";
        return
    }
    if (zcoUword2.value.length ==0) {
        zcoError.innerHTML = "请再次输入密码";
        return
    }
    if (zcoUword1.value()!=zcoUword2.value()){
        zcoError.innerHTML="两次密码不一致"
        isError=false;
                return isError;
    }
    return isError;
    window.alert("注册成功!!
{% extends ‘daohang.html‘ %}
{% block title %}注册{% endblock %}
{% block head %}
    <link rel="stylesheet" type="text/css" href="{{ url_for(‘static‘,filename=‘css/zhuce.css‘) }}">
    <script src="{{ url_for(‘static‘,filename=‘js/zhuce.js‘) }}"></script>
{% endblock %}
 
{% block main %}
    <div class="box">
        <h2>注册</h2>
        <form action="{{ url_for(‘zhuce‘) }}" method="post">
            <div class="input_box">
                <input id="uname" type="text" placeholder="请输入用户名" name="username">
            </div>
            <div class="input_box">
                <input id="upass" type="password" placeholder="请输入密码" name="password">
            </div>
            <div class="input_box">
                <input id="upass1" type="password" placeholder="请再次输入密码">
            </div>
            <div id="error_box"><br></div>
            <div class="input_box">
                <button onclick="fnzhuce()">注册</button>
            </div>
        </form>
    </div>
{% endblock %}

 

完成注册功能

标签:rip   获取   url   else   ace   i++   eth   用户名   pass   

原文地址:http://www.cnblogs.com/xiepingjian/p/7872428.html

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