python - Flask_login 是否自动设置 "next"参数?

标签 python flask flask-login

我使用 Flask Login 创建了一个登录和注销页面。我尝试在不先登录的情况下导航到注销页面,但我不断被重定向到此处:http://127.0.0.1:5000/login?next=%2Findex

这是我的注销功能:

from flask import render_template, flash, redirect, url_for, request
from app import app
from app.forms import LoginForm, RegistrationForm
from flask_login import current_user, login_user, logout_user, login_required
from app.models import User
from app import db

@app.route('/logout')
def logout():
    logout_user()
    return redirect(url_for('index'))

最佳答案

您正在重定向到需要用户登录的 View ,因此设置了 next= 值。

@app.route('/')
@login_required # <-- Your index view has this.
def index():
    return 'Index'

在用户注销时将用户重定向到不需要登录的页面或没有 @login_required 装饰器的页面。

关于python - Flask_login 是否自动设置 "next"参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57533436/

相关文章:

python - 无法使用 Supervisord 启动 Python 应用程序

python - 将 RoleNeed 与 Flask Principal 相结合

python - Flask 和 Flask_login - 组织代码

python - 手动调用matplotlib的draw

Python 将 float 写入 Postgresql,但精度较低

python - Django select_related 不起作用

python - 有效整合concurrent.futures并行执行的结果?

python - flask "hello world"无法在 Debug模式下运行

python - 正确使用 Flask-ldap

python - Flask、Flask-Login 和 Socket.io : Keep a session active even when not sending requests