I'm new to flask web development, I'm trying to render a template containing a form, and validate information from the form. I'm getting the following error
app\views.py", line 47, in signup
if form.validate_on_submit():
TypeError: validate_on_submit() missing 1 required positional argument: 'self'
here's my code:
# app/views.py
from .forms import SignUp
from .models import User
@app.route('/signup', methods=["GET", "POST"])
def signup():
form = SignUp
if form.validate_on_submit():
user = User(
email=form.email.data,
username=form.username.data,
first_name=form.first_name.data,
last_name=form.last_name.data
)
db.session.add(user)
db.session.commit()
return 'success'
return render_template('signup.html', form=form)
forms
#app/forms.py
from flask_wtf import FlaskForm
from wtforms import StringField, SubmitField
from wtforms.fields.html5 import EmailField
from wtforms.validators import DataRequired, Email
class SignUp(FlaskForm):
email = EmailField('Email', validators=[DataRequired(), Email()])
username = StringField('Username', validators=[DataRequired()])
first_name = StringField('First Name', validators=[DataRequired()])
last_name = StringField('Last Name', validators=[DataRequired()])
submit = SubmitField('Sign Up')
models:
#app/models.py
from app import db
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(60), index=True, unique=True)
username = db.Column(db.String(60), index=True, unique=True)
first_name = db.Column(db.String(60), index=True)
last_name = db.Column(db.String(60), index=True)
error is from the views file at: validate_on_submit(), i have included my models and forms code as well. I have done as recommended in this post TypeError validate on submit missing required positional argument but i still get the same error
答案 0 :(得分:1)
更改此行
public ThirdPartyResponse load(ThirdPartyRequestContext context) {
ThirdPartyResponse thirdPartyResponse = new ThirdPartyResponse();
try
{
thirdPartyResponse.setData(getData(context));
}catch (Exception e)
{
LOGGER.error("Error executing {}", context.getEndpoint(), e);
thirdPartyResponse.setData(Collections.emptyList());
thirdPartyResponse.setErrorMessage(e.getMessage());
}
return thirdPartyResponse;
}
对此:
form = SignUp
答案 1 :(得分:0)
您需要实例化 form = SignUp()
表单
SignUp