def account(): form = UpdateUserForm() if form.validate_on_submit(): print(form) if form.picture.data: username = current_user.username pic = add_profile_pic(form.picture.data, username) current_user.profile_image = pic current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('User Account Updated') return redirect(url_for('users.account')) elif request.method == 'GET': form.username.data = current_user.username form.email.data = current_user.email profile_image = url_for('static', filename='profile_pics/' + current_user.profile_image) return render_template('account.html', profile_image=profile_image, form=form)
def account(): form = UpdateUserForm() if form.validate_on_submit(): # if a new picture is uploaded if form.picture.data: username = current_user.username # pic is the path of the saved image pic = add_profile_pic(form.picture.data, username) current_user.profile_image = pic current_user.username = form.username.data current_user.email = form.email.data db.session.commit() flash('Account information updated!') return redirect(url_for('users.account')) elif request.method == 'GET': # grabbing current info of they have not submitted yet form.username.data = current_user.username form.email.data = current_user.email profile_image = url_for('static', filename=('profile_pics/' + current_user.profile_image)) return render_template('account.html', profile_image=profile_image, form=form)