美文网首页
Dash与Flask结合实现多页面调转

Dash与Flask结合实现多页面调转

作者: 菜鸟笔记 | 来源:发表于2021-02-02 09:24 被阅读0次

    from dash import Dash
    from werkzeug.wsgi import DispatcherMiddleware
    import flask
    from werkzeug.serving import run_simple
    import dash_html_components as html

    server = flask.Flask(name)
    dash_app1 = Dash(name, server = server, url_base_pathname='/dashboard/' )
    dash_app2 = Dash(name, server = server, url_base_pathname='/reports/')
    dash_app1.layout = html.Div([html.H1('Hi there, I am app1 for dashboards')])
    dash_app2.layout = html.Div([html.H1('Hi there, I am app2 for reports')])
    @server.route('/')
    @server.route('/hello')
    def hello():
    return 'hello world!'

    @server.route('/dashboard')
    def render_dashboard():
    return flask.redirect('/dash1')

    @server.route('/reports')
    def render_reports():
    return flask.redirect('/dash2')

    app = DispatcherMiddleware(server, {
    '/dash1': dash_app1.server,
    '/dash2': dash_app2.server
    })

    run_simple('0.0.0.0', 8050, app, use_reloader=True, use_debugger=True)

    werkzeug要升级到0.16以上,否则报错。

    相关文章

      网友评论

          本文标题:Dash与Flask结合实现多页面调转

          本文链接:https://www.haomeiwen.com/subject/aiietltx.html