Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
get all data from fields in a WTForm as dict
"""
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
You can’t perform that action at this time.