Mendapatkan pengecualian saat menjalankan kode berikut untuk validasi formulir.
File "/Users/homeduvvuri/Documents/Learning/PartyGoUdemy/PartGo/user/forms.py", line 11, in BaseUserForm
email = EmailField('Email', [validators.DataRequired(), validators.Email()])
File "/Users/homeduvvuri/Documents/Learning/PartyGoUdemy/PartGo/partgo-env/lib/python3.7/site-packages/wtforms/validators.py", line 332, in __init__
raise Exception("Install 'email_validator' for email validation support.")
Exception: Install 'email_validator' for email validation support.
Berjalan dengan sempurna di codeanywhere VM. Tidak pada mesin lokal.
from flask_wtf import FlaskForm
from flask_wtf.file import FileField, FileAllowed
from wtforms import Form, StringField, PasswordField, validators, ValidationError
from wtforms.validators import InputRequired, Email
from wtforms.fields.html5 import EmailField
from wtforms.widgets import TextArea
from user.models import User
class BaseUserForm(FlaskForm):
name = StringField('Name', [validators.DataRequired(), validators.Length(min=2, max=30)])
email = EmailField('Email', [validators.DataRequired(), validators.Email()])
Jawaban:
Jika Anda melihat file wtforms / validators.py di baris 9:
Cukup instal paket:
sumber
Exception: Install 'email_validator' for email validation support.
Saya memiliki masalah yang sama dengan pembaruan terbaru, mencoba menginstal email_validator dan flask-validator dan melanjutkan pengecualian ini. Dipecahkan dengan menambahkan persyaratan.txt baris berikut: email-validator == 1.0.5 seperti yang disarankan [di sini]. ( Https://github.com/alphagov/notifications-admin/commit/5ce2906c5aa6d16 )
sumber
Jika Anda ingin menginstalnya dengan
wtforms
:sumber