I am using Flask to develop a web application. I was originally doing HTML forms manually, and then switched over to using WTForms (this is an educational project, so I am showing each step of building the project).
I got a bit confused when trying to add HTML5 form fields, such as EmailField. I searched the WTForms documentation, and online, and I couldn't find out how to create a WTForm using an HTML5 EmailField.
I then installed this module https://pypi.python.org/pypi/wtforms-html5 which allowed for it, and everything worked. But I was unhappy about adding an extra dependency, especially as it doesn't seem to be actively developed (https://github.com/brutus/wtforms-html5).
I then ended up on the WTForms github page, and found that actually there is support for all the new HTML5 fields, but that these fields aren't imported by default. https://github.com/wtforms/wtforms/blob/master/wtforms/fields/html5.py Therefore instead of using
from WTForms import EmailField
As one would infer from
from WTForms import TextField
One instead has to use
from wtforms.fields.html5 import EmailField
I was previously using the wtforms-html5 module as follows
from wtforms_html5 import EmailField
I therefore changed all occurrences of wtforms_html5
to wtforms.fields.html5
and my application is working exactly as expected.
Ok, thanks for reading all the background. Now for the questions:
Why aren't any of the html5 fields (EmailField, DateField, etc) mentioned in the WTForms documentation?
Why aren't these fields imported into WTForms by default like the others
Are these fields stable/ intended for use?
What's best practice for importing fields from WTForms?
For Text field, I can use any of the following:
from wtforms import TextField
from wtforms.fields import TextField
from wtforms.fields.simple import TextField
But for EmailField, I have to use
from wtforms.fields.html5 import EmailField
I would like:
from wtforms.fields import TextField
from wtforms.fields import EmailField
But this would require adding a line to the fields [__init__][1]
file, which I am unwilling to do as it is an educational project and this would just confuse the learners.
I am looking for
- Insight as to why WTForms does not document or by default import the html5 fields
- Any reason to continue using the wtforms-html5 third-party module.