flask-wtf populate form code example
Example 1: how to pre populate field flask wtforms
form.populate_obj(user)
user.site = form.website.data
db.session.commit()
Example 2: how to pre populate field flask wtforms
@decorator_authorized_user
def editprofile(nickname = None):
form = EditProfile()
form_action = url_for('profile.editprofile')
my_user = Users.get(...)
if request.method == 'GET':
form.username.data = my_user.username
form.email.data = my_user.email
if form.validate_on_submit():
if form.username.data == nickname:
query = EditProfile(form.username.data,
form.email.data,
form.about.data,
form.website.data,
)
print query
db.session.add(query)
db.session.commit()
flash('User Updated')
print "added"
return(url_for('profile.editprofile'))
return render_template('profile/add.html', form=form,
form_action=form_action, title="Update Profile")