首页 > 解决方案 > InvalidConfig:`routes_pathname_prefix` 需要在登录页面以 `/` 结尾

问题描述

我正在尝试使用烧瓶在破折号中为我的仪表板应用程序创建一个登录页面

我正在尝试运行此代码,但出现此错误。

请告诉我应该做什么以及如何解决此错误

# -*- coding: utf-8 -*-
import os
from flask import Flask
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
from dash import Dash
from dash_flask_login import FlaskLoginAuth
import sqlite3
import hashlib
from flask_login import UserMixin

# Setup the Flask server
server = Flask(__name__)

# config
server.config.update(
    SECRET_KEY = os.urandom(12),
)

# Create our initial Dash App
app = Dash(name='app1', url_base_pathname='/app1', server=server)

auth = FlaskLoginAuth(app, use_default_views=True)

app.layout = html.Div(children=[
    html.H1(children='Hello Dash'),

    html.Div(children='''
        Dash: A web application framework for Python.
    '''),

    dcc.Graph(
        id='example-graph',
        figure={
            'data': [
                {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
                {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
            ],
            'layout': {
                'title': 'Dash Data Visualization'
            }
        }
    ),
    html.A(dcc.Input(value='Log Out', type='submit'), href='/logout', )
])

app.css.append_css({
    'external_url': 'https://codepen.io/chriddyp/pen/bWLwgP.css',
})

# Run the server
if __name__ == '__main__':
    server.run(debug=True, port=8050)

标签: pythonflaskplotly-dash

解决方案


requests_pathname_prefix必须以routes_pathname_prefix. 如果您在此更新之前同时提供了请求和路由路径名,请确保 requests_pathname_prefix 以与routes_pathname_prefix.

只需在末尾添加“/”即可。它是您使用的版本中的标准。 在此处输入链接描述

app = Dash(name='app1', url_base_pathname='/app1/', server=server)

推荐阅读