def account(username): form = UpdateAccountInfo() if form.validate_on_submit(): user = User.update( name=form.name.data, email=form.email.data, username=form.username.data).where(User.id == current_user.id) if form.photo.data: photoname = save_photo(form.photo.data) User.update(photo=photoname).where( User.id == current_user.id).execute() os.rename( os.path.join(current_app.root_path + '/static/photos/', current_user.username), os.path.join(current_app.root_path + '/static/photos', form.username.data)) user.execute() flash('Account updated', 'success') return redirect(url_for('.account', username=username)) if request.method == meth[1]: form.email.data = current_user.email form.name.data = current_user.name form.username.data = current_user.username return render_template('home/account.html', form=form)