相关疑难解决方法(0)

为什么Flask的url_for在Python中对该项使用装饰器时会抛出错误?

我正在创建一个Python Flask应用程序,并在下面创建了装饰器和视图.装饰器在查看索引时效果很好,但是当您注销并使用url_for索引重定向时,它会抛出一个构造函数.为什么会

def logged_in(fn):
    def decorator():
        if 'email' in session:
            return fn()
        else:
            return render_template('not-allowed.html', page="index")
    return decorator


@app.route('/')
@logged_in
def index():
    email = session['email']    
    return render_template('index.html', auth=True, page="index", marks=marks)

@app.route('/sign-out')
def sign_out():
    session.pop('email')
    print(url_for('index'))
    return redirect(url_for('index'))
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?错误是:BuildError: ('index', {}, None)

python decorator build-error flask

5
推荐指数
1
解决办法
1075
查看次数

标签 统计

build-error ×1

decorator ×1

flask ×1

python ×1