Infinite edit_profile redirect
paulsonak opened this issue · 2 comments
paulsonak commented
Thanks for the great tutorial!!
I'm working through chapter 6 and as far as I can tell, my code is the same as v0.6, but my packages may be newer (Flask 2.0.3, flask-wtf 0.15.1).
When I define the edit_profile route, I get an infinite redirect loop after clicking the 'edit profile' link. This additionally has the effect of deleting my username but not email from the database, which causes a bunch of other weird problems. But, if I switch the order of the if and elif statements so that it checks whether the request is a GET first, everything works again:
@app.route('/edit_profile', methods=['GET','POST'])
@login_required
def edit_profile():
form=EditProfileForm()
if request.method=='GET':
form.username.data=current_user.username
form.about_me.data=current_user.about_me
elif form.validate_on_submit:
current_user.username = form.username.data
current_user.about_me = form.about_me.data
db.session.commit()
flash('Your changes have been saved.')
return redirect(url_for('edit_profile'))
return render_template('edit_profile.html', title='Edit Profile', form=form)
My conda env:
conda_packages.txt
miguelgrinberg commented
You are missing the parentheses aftervalidate_on_submit
.
paulsonak commented
Ah, thank you!