这是注册表格的路径
@app.route("/register", methods=['GET', 'POST'])
def register():
form = RegisterForm()
if form.validate_on_submit():
print(f"value submitted")
# flash(f'Account created for {form.name.data}!', 'success')
return redirect(url_for('homeLogin'))
print("not validated")
return render_template('dashboard/register.html',form=form)
这是froms.py文件
from wtforms import validators
from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField, BooleanField , SelectField
from wtforms.validators import DataRequired, Length, Email, EqualTo
from pycountry import pycountry
from flask_wtf import Form
# Register Form Class
class RegisterForm(Form):
name = StringField('Username', [Length(min=1, max=50)])
company = StringField('company', [Length(min=4, max=25)])
email = StringField('Email', validators=[DataRequired(), Email()])
password = PasswordField('Password', [ DataRequired(), EqualTo('confirm', message='Passwords do not match') ])
confirm = PasswordField('Confirm Password')
country = SelectField(u'Country', choices=[(country.alpha_2, country.name) for country in pycountry.countries] , validate_choice=True)
submit = SubmitField('Sign Up')
我的主文件导入:
from app import app as app
from flask import Flask,render_template,request,session,redirect,url_for , flash
import helperFunctions as hf
from model import *
import math
from datetime import datetime
from forms import RegisterForm
运行python文件将输出显示为:
FlaskTFTFDeprecationWarning:“ flask_wtf.Form”已重命名为“ FlaskForm”,并将在1.0中删除。 表格= RegisterForm()
未验证
答案 0 :(得分:0)
在您的注册路线中,尝试使用: 如果form.validate(): ...
代替使用form.validate_on_submit()