Example #1
0
def edit_profile():
    form = EditProfileForm(current_user.username, current_user.email)
    if form.validate_on_submit() or form.validate_username_email(
            form.username.data,
            form.email.data):  #if true, then save the entered data to db
        current_user.username = form.username.data
        current_user.email = form.email.data
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash(_('your changes have been saved'))
        return redirect(url_for('edit_profile'))
    elif request.method == 'GET':  #if it is a get request, pre-populate the fields with already saved data
        form.username.data = current_user.username
        form.email.data = current_user.email
        form.about_me.data = current_user.about_me
    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form)