@app.route('/account', methods=['GET', 'POST'])
@login_required
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            old_picture = current_user.image_file
            old_picture_path = os.path.join(app.root_path, 'static/profile_pics', old_picture)
            if os.path.exists(old_picture_path):
                os.remove(old_picture_path)
            else:
                print(('The file does not exist ' + old_picture))
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Your account has been updated!', 'success')
        return redirect(url_for('account'))
    elif (request.method == 'GET'):
        form.username.data = current_user.username
        form.email.data = current_user.email
    image_file = url_for('static', filename=('profile_pics/' + current_user.image_file))
    return render_template('account.html', title='Account', image_file=image_file, form=form)
@app.route('/account', methods=['GET', 'POST'])
@login_required
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            old_picture = current_user.image_file
            old_picture_path = os.path.join(app.root_path, 'static/profile_pics', old_picture)
            if os.path.exists(old_picture_path):
                os.remove(old_picture_path)
            else:
                print(('The file does not exist ' + old_picture))
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Your account has been updated!', 'success')
        return redirect(url_for('account'))
    elif (request.method == 'GET'):
        form.username.data = current_user.username
        form.email.data = current_user.email
    image_file = url_for('static', filename=('profile_pics/' + current_user.image_file))
    return render_template('account.html', title='Account', image_file=image_file, form=form)