0
那裏。 我定義的類名爲LoginForm的:如何在flask-wtf表格中自定義字段
class LoginForm(FlaskForm):
email = StringField('Email', validators=[DataRequired(), Length(5, 64), Email()])
password = PasswordField('Password', validators=[DataRequired()])
remember_me = BooleanField('Remember me')
submit = SubmitField('Log In')
然後我呈現在模板login.html
:
{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{{ wtf.quick_form(form) }}
而且我認爲這是一個有點醜陋。所以,我呈現在正常方式字段:
<form action="" method="POST" role="form" class="form">
{{ form.hidden_tag() }} {{ wtf.form_errors(form, hiddens="only") }}
<div class="form-group required">
<label class="control-label" for="email">Email</label>
{{ form.email(class="form-control",id="email",required="required",type="text",value="",placeholder="Enter email") }}
</div>
<div class="form-group required">
<label class="control-label" for="password">Password</label>
{{ form.password(class="form-control",id="password",required="required",type="password",value="",placeholder="Enter email") }}
</div>
<div class="checkbox">
<label>
<input id="remember_me" name="remember_me" type="checkbox" value="y"> Remember me
</label>
</div>
{{ form.submit(class="btn btn-success btn-block") }}
<a href="{{ url_for('auth.register') }}" class="btn btn-danger btn-block" role="button">Register</a>
</form>
現在同意我的看法。但是我遇到了一個問題:當我點擊綠色登錄按鈕時,它不驗證數據(如電子郵件地址的格式)。我應該如何解決這個問題?
您確定無法驗證或不顯示任何錯誤嗎? –
@BurhanKhalid謝謝,我明白了。它只是不顯示錯誤。 –