【发布时间】:2021-09-10 18:47:10
【问题描述】:
我正在使用 firebase 身份验证来验证我的烧瓶应用程序。这适用于所有烧瓶视图。但是,我无法让它与破折号视图一起使用。我在下面附上了一个非常简单的没有firebase的最小示例,其中我有一个烧瓶页面hello和一个dashboard页面。我用装饰器check_token() 包装视图,它目前应该只是将所有视图重定向到登录页面。这适用于烧瓶视图/hello 和/,但不适用于破折号视图dashboard。
令人困惑的是,装饰器甚至没有为仪表板视图运行,打印语句证明了这一点。
routes.py
from flask import current_app as app
def check_token(f):
print("RUNNING check_token")
def wrap(*args,**kwargs):
print("RUNNING wrap")
token = request.cookies.get("token")
if not token:
return redirect(url_for('login'))
return f(*args, **kwargs)
wrap.__name__ = f.__name__
return wrap
@app.route('/')
@app.route('/hello')
@check_token
def hello():
return 'hello world!'
@app.route('/login')
def login():
return "This is the login page"
@app.route('/dashboard')
@check_token
def render_dashboard():
return redirect('/dash1')
application.py
from dash import Dash
from werkzeug.middleware.dispatcher import DispatcherMiddleware
from werkzeug.serving import run_simple
import dash_html_components as html
from flask import Flask, request,render_template, url_for, redirect
def init_dash(dash_app1):
dash_app1.layout = html.Div([html.H1('Hi there, I am app1 for dashboards')])
return dash_app1
def init_app():
server = Flask(__name__)
dash_app1 = Dash(__name__, server = server, url_base_pathname='/dashboard/' )
dash_app1 = init_dash(dash_app1)
with server.app_context():
import routes
app = DispatcherMiddleware(server, {
'/dash1': dash_app1.server,
})
return app
if __name__ == "__main__":
run_simple('0.0.0.0', 8090, init_app(), use_reloader=True, use_debugger=True)
任何帮助将不胜感激!过去两天我一直在努力尝试完成这项工作
【问题讨论】:
标签: authentication flask plotly-dash werkzeug