gpt4 book ai didi

python - 如何在不使用 iframe 的情况下结合 Dash 和 Flask 登录?

转载 作者:行者123 更新时间:2023-12-01 07:17:37 25 4
gpt4 key购买 nike

我有一个 Flask 应用程序,该应用程序的某些页面受 Flask-Login 保护,我需要将破折号图添加到我的应用程序中,该图应该位于需要身份验证的页面上。我应该补充一点,除了 Flask Login 之外,我还使用 Flask session 创建了用户访问级别。

我找到了如何使用 iframe block 将 Dash 与 protected 页面结合起来,但我想尝试将破折号图制作为具有用户身份验证的单独页面(而不是 iframe)。如果忘记身份验证,我可以在 Flask 应用程序中将破折号图添加为单独的页面。

通常我会执行以下操作来检查登录:

@app.route("/somempage", methods=["GET", "POST"])
@flask_login.login_required
def return_somepage():
active_username = session['user_id']
try:
HOST, USER, PASSWORD, AUTH_PLUGIN =
InitSetup.read_mysql_init_config_file(WORKDIR +
os.path.join(os.getcwd(), "mosreg_webscrap_website.config.txt"))
conn, curs = MySQLOP.create_mysql_connection(HOST, USER, PASSWORD,
AUTH_PLUGIN)
active_user = MySQLOP.retrieve_userinfo_from_db(curs,
active_username)
#now we check value of db colum and decide if user can see the page:
if active_user[0][4]:
#show page
else:
# return user have no rights to see the page template

最佳答案

我使用以下命令成功在我的仪表板应用中添加了 @login_required:

在 Flask 应用程序的 __init__.py 中

app = Flask(__name__, instance_relative_config=False)

# other stuff ...

@app.route("/dash", methods=['POST','GET'])
@login_required
def dash():
return appdash.index()

在 dashapp.py
appdash = dash.Dash(__name__, external_stylesheets=external_stylesheets, server=app)

请注意,我没有在 Dash 应用程序声明中定义路线(即 routes_pathname_prefix='/dash'),因此 Dash 应用程序只能通过我的 Flask 应用程序的路线查看,即我输入了@login_required

@login_required 在我的例子中是来自 Flask tutorial 的那个

关于python - 如何在不使用 iframe 的情况下结合 Dash 和 Flask 登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57873247/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com