程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了DispatcherMiddleware 问题 - flask + dash 应用程序集成大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决DispatcherMiddleware 问题 - flask + dash 应用程序集成?

开发过程中遇到DispatcherMiddleware 问题 - flask + dash 应用程序集成的问题如何解决?下面主要结合日常开发的经验,给出你关于DispatcherMiddleware 问题 - flask + dash 应用程序集成的解决方法建议,希望对你解决DispatcherMiddleware 问题 - flask + dash 应用程序集成有所启发或帮助;

我正在尝试使用 Flask' DispatcherMiddleware

同时运行 Flask 和 Dash 应用程序

我的仪表板应用程序是一个多页应用程序。 App的结构如下:

Deploy-Auth
- auth
  - templates
  - - base.HTML
  - - login.HTML
  - init.py
  - routes.py 
- dashapp.py
- app.py
- procfile
- requirements.txt

app.py 的内容

app = dash.Dash(__name__)

server = app.server

app.config.update({

    'routes_pathname_prefix': '','requests_pathname_prefix': ''
})

dashapp.py 的内容

# App Layout
app.layout = HTMl.div([

    # header
    HTMl.div([

        
        dcc.link(
            href=('/home'),children='Home',style={'paddingRight': 10}
        ),dcc.LOCATIOn(ID='url'),HTMl.div(ID='page-content',style={'margin-left': '2%'}),)

])



# Render page content
@app.callBACk(Output("page-content","children"),[
                input('url','pathname')
              ]
             )
def display_content(pathName):

    if pathname == '/home':
        return home.layout

    elif pathname == '/archive':
        return archive.layout()

    else:
        return home.layout

routes.py 的内容

from app import app
imports .........

main = Blueprint('main',__name__)

@main.route('/')
def index():
    if not current_user.is_authenticated:
        return render_template('login.HTML')
    else:
        return redirect(url_for('main.profile'))

@main.route('/profile')
@login_required
def profile():
    email = current_user.email
    user = User.query.filter_by(email=email).first()
    user_obj = {'fullname':user.fullname,'email':user.email,}
    return render_template('profile.HTML',user=user_obj)

init.py 的内容

from flask import Flask,redirect
from flask_sqlalchemy import sqlAlchemy
from flask_login import LoginManager,login_required
from app import app as dashApp

server_auth = Flask(__name__,instance_relative_config=falsE)

server_auth.config['SECRET_KEY'] = 'xxxxxxxxxxxx'
server_auth.config['sqlALCHEmy_database_URI'] = 'sqlite:///db.sqlite'
server_auth.config['sqlALCHEMY_TRACK_MODIFICATIONS'] = false

# init sqlAlchemy so we can use it later in our models
db = sqlAlchemy(server_auth)

# def create_app():

db.init_app(server_auth)

login_manager = LoginManager()
login_manager.login_vIEw = 'auth.login'
login_manager.init_app(server_auth)

from .models import User,init_db
init_db() # created sqlite tables

@login_manager.user_loader
def load_user(user_iD):
    return User.query.get(int(user_iD))

# blueprint for auth routes in our app
from .auth import auth as auth_blueprint
server_auth.register_blueprint(auth_blueprint)

# blueprint for non-auth parts of app
from .main import main as main_blueprint
server_auth.register_blueprint(main_blueprint)

app = dispatcherMIDdleware(server_auth,{
    '/dashboard': dashApp.server,#add dash routes
    })

if __name__ == '__main__':
    run_simple('0.0.0.0',5000,app,use_reloader=True,use_deBUGger=TruE)

应用程序的入口点,登录页面有效。但是,当我点击 dashboard 导航到 dashApp 时,我得到一个 404 Not Found error

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的DispatcherMiddleware 问题 - flask + dash 应用程序集成全部内容,希望文章能够帮你解决DispatcherMiddleware 问题 - flask + dash 应用程序集成所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。