我使用 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/