Created
November 2, 2020 14:02
-
-
Save tassaron/b17d16b502c13431cc5dfe90aa51dadc to your computer and use it in GitHub Desktop.
get all data from fields in a WTForm as dict
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
It took me hours to figure out that iterating over fields | |
in a WTForm has unintuitive behaviour if you use `continue` | |
""" | |
# This works as expected | |
for field in form._fields: | |
data[field] = form._fields[field].data | |
del data["csrf_token"] | |
del data["submit"] | |
# This doesn't work as expected | |
for field in form._fields: | |
if field in ("csrf_token", "submit"): | |
continue | |
data[field] = form._fields[field].data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment