flask-login login_required装饰器页面不跳转

flask-login login_required装饰器页面不跳转

装饰函数

@app.route('/add', methods=['POST'])

@login_required

def add():

todo = request.get_json()['todo']

todo_document = {

'content': todo,

'status': 0,

'date': datetime.now()

}

db.create(todo_document)

return 'added'

跳转页面

login_manager.login_view = 'login'

登录视图

@app.route('/login', methods=['GET', 'POST'])

def login():

login_form = LoginForm()

if login_form.validate_on_submit():

username = login_form.username.data

password = login_form.password.data

user = User.objects(username=username).first()

if user is not None and check_password_hash(user.password, password):

login_user(user)

next = request.args.get('next')

if next is None or not next.startswith('/'):

next = url_for('index3')

return redirect(next)

flash('用户名或密码错误!')

return render_template('login.html', form=login_form)

F12查看请求,发现add已经跳转到login,login视图响应内容也是login.html,但是页面却没有跳转到login.html。求指导额!

以上是 flask-login login_required装饰器页面不跳转 的全部内容, 来源链接: utcz.com/a/164276.html

回到顶部