我是新来的Flask,请帮帮我..从最近1小时开始,我就一直在解决这个问题。
from flask_wtf import FlaskForm as Form
from wtforms import StringField, TextAreaField, PasswordField, validators
from wtforms.validators import DataRequired
class RegistrationForm(Form):
name = StringField('Name:', [validators.Length(min=1, max=50), validators.DataRequired(
)])
email = StringField('Email:', [validators.Length(min=6, max=90), validators.DataRequired(
)])
username = StringField('Username:', [validators.Length(min=4, max=30), validators.DataRequired(
)])
password = PasswordField('Password:', [validators.DataRequired(
), validators.equal_to('confirm_password', "Password do not match")])
confirm_password = PasswordField('Confirm Password')
@app.route("/register", methods=['GET', 'POST'])
def register():
form = RegistrationForm(request.form)
if(request.method == 'POST' and form.validate()):
name = form.name.data
email = form.email.data
username = form.username.data
password = sha256_crypt.encrypt(str(form.password.data))
curr = mysql.connection.cursor()
curr.execute("INSERT INTO users(name,emailid,username,password) VALUES(%s,%s,%s,%s)",
(name, email, username, password))
mysql.connection.commit()
flash('You are now registered and can log in', 'success')
return redirect(url_for("login"))
return render_template("register.html", form=form)