我正在使用flask-login和flask-mongoengine编写一个简单的烧瓶应用程序,一切正常,直到我更新了项目所需的所有python插件 . 现在,flask将不会登录 . 当我登录并验证表单时,它会返回登录页面,其中包含url:http://localhost:5000/auth/login?next=%2Findex ...我认为 %2F
可能与此问题有关 .
这是我的登录视图:
@bp.route('/login', methods=['GET', 'POST'])
def login():
if current_user.is_authenticated:
return redirect(url_for('main.index'))
form = LoginForm()
if form.validate_on_submit():
user = User.objects(username__exact=form.username.data).first()
if user is None or not user.check_password(form.password.data):
flash(_('Invalid username or password'))
return redirect(url_for('auth.login'))
login_user(user, remember=form.remember_me.data)
next_page = request.args.get('next')
if not next_page or url_parse(next_page).netloc != '':
next_page = url_for('main.index')
return redirect(next_page)
return render_template('auth/login.html', title=_('Sign In'), form=form)
我正在使用WTForms,我可以确认表格 action=""
这是从flask megatutorial改编的,但我使用的是MongoDB .
1 回答
问题解决了!
当我将应用程序从使用SQL转换为MongoDB时,我错误地将load_user函数设置为:
但实际上load_user函数需要接受
id
字段作为接口,因此该函数应如下所示: