@web.route('/login', methods=['GET', 'POST'])
def login():
form = LoginForms(request.form)
if request.method == 'POST' and form.validate():
user = User.query.filter_by(nickname=form.nickname.data).first()
if user and user.check_password(form.password.data):
login_user(user)
next = request.args.get('next')
# if not next or not next.startswith('/'):
# next = url_for('web.login')
return "%s" %next
else:
flash('账号不存在或密码错误', category='login_error')
return render_template('auth/login.html', form=form)7月老师深入浅出剖析Flask核心机制,和你一起探讨Python高级编程
了解课程