尝试访问注册页面时,获取注册表单没有属性“确认”错误

时间:2019-05-06 15:31:34

标签: python flask flask-wtforms

我遇到以下错误:

jinja2.exceptions.UndefinedError: '__main__.RegisterForm object' has 
no attribute 'confirm'

当我尝试访问/注册路线时 我已经使用WTF表单进行登录和注册

这是用户的数据库:

  class User(UserMixin, db.Model):
  id = db.Column(db.Integer,primary_key=True)
  username = db.Column(db.String(20),unique=True)
  email = db.Column(db.String(50),unique=True)
  password=db.Column(db.String(70))
  address = db.Column(db.String(150))

这是注册表格(Wtf表格):

  class RegisterForm(FlaskForm):
  email = StringField('email',validators= 
  [InputRequired(),Email(message='Invalid email'), Length(max=50)])
  username = StringField('username', validators=[InputRequired(), 
  Length(min=5, max=20)])
  password = StringField('password', validators=[InputRequired(), 
  Length(min=8,max=70)])

注册页面功能:

  #Signup page
  @app.route('/signup',methods=['GET', 'POST'])
  def signup():
  form = RegisterForm()

   if form.validate_on_submit():
    hashed_password = generate_password_hash(form.password.data, 
   method='sha256')
    if User.query.filter_by(username=form.username.data).first() == 
   form.username.data:
        print("Username already exists")

    new_user = User(username=form.username.data, 
    email=form.email.data, password=hashed_password)
    db.session.add(new_user)
    db.session.commit
    return redirect(url_for('login'))
   return render_template('signup.html', title='Signup', form=form)

注册页面的HTML代码:

 <h1>REGISTER</h1>

 {% from "_util.html" import render_field %}
 <form id="loginForm" class="form form-register" method="POST" 
  action="" role="form">
  {{ form.hidden_tag() }}
  {{ render_field(form.username, placeholder="Username") }}<br>
  {{ render_field(form.email, placeholder="Email") }}<br>
  {{ render_field(form.password, placeholder="Password") }}<br>
  <p><input class="btn btn-default btn-submit" type="submit" 
  value="Login"></p>
  </form>

  <a href="/">index</a><br>
  <a href="/login">login</a><br>

0 个答案:

没有答案