我正在关注米格尔先生关于烧瓶的书。我被困在登录功能中,我向用户发送电子邮件确认,然后单击链接后,它会要求用户登录,但登录后 request.args.get('next') 变量为空,因此确认函数永远不会被执行。我怀疑这是由于 before_app_request 引起的。我对烧瓶很陌生,我花了两天时间试图解决这个问题。米格尔的版本工作正常,我的版本似乎被诅咒了。确实需要别人的观点。谢谢阅读。
视图.py
@auth.before_app_request
def before_request():
print("\tREQUEST ENDPOINT ::"+str(request.endpoint))
print("\tREQUEST ARGS ::"+str(request.args.get('next')))
if current_user.is_authenticated \
and not current_user.confirmed \
and request.endpoint \
and request.endpoint[:5] != 'auth.' \
and request.endpoint != 'static':
return redirect(url_for('auth.unconfirmed'))
@auth.route('/register', methods=['GET','POST'])
def register():
form=RegForm()
if form.validate_on_submit():
user=User(fname=form.fname.data,
lname=form.lname.data,
email=form.email.data,
organization_name=form.username.data,
password=form.password.data)
db.session.add(user)
#db.session.commit()
token=user.generate_confirmation_token()
send_email(user.email,'Confirm your Account','email/auth/confirm',user=user,token=token)
flash('A confirmation Email has been sent, Please check your inbox','success')
return redirect(url_for('auth.login'))
#except Exception as e:
# print("LINE 48 EMAIL: "+str(e))
# db.session.rollback()
return render_template('Landing/entry.html',form=form)
@auth.route('/confirm/<token>') …Run Code Online (Sandbox Code Playgroud)