python - 从烧瓶应用程序运行破折号请求会出现 404 错误,而其他烧瓶路由运行良好
问题描述
我正在尝试将使用 dash 构建的仪表板集成到执行其他操作的烧瓶应用程序中。我希望它在http://127.0.0.1:5000/Dashboard上显示仪表板。我翻了很多资源,还是不清楚。该 URL 不断给我一个 404 Not found 错误,但所有其他烧瓶路由的 URL 都有效。
应用程序.py
from flask import Flask, render_template, request, redirect
import flask
from dashboard import *
app = Flask(__name__)
@app.route('/Recalculate', methods = ['GET','POST'])
def calculate():
return render_template('recalculate.html', tables=[final_merged_data.to_html(classes='data', index=False)], titles=round_data.columns.values)
@app.route('/Dashboard')
def render_dashboard():
return redirect("/pathname/")
if __name__ == '__main__':
app.run(debug=True)
仪表板.py
import dash
import flask
from flask import Flask
import dash_table
import numpy
import dash_core_components as dcc
import dash_html_components as html
external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']
server = flask.Flask(__name__)
app_dash = dash.Dash(__name__,server=server, routes_pathname_prefix="/pathname/", external_stylesheets=external_stylesheets)
colors = {
'background': '#111111',
'text': '#7FDBFF'
}
# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
data = [trace1, trace2]
layout = go.Layout(barmode = 'group',xaxis_title="Day of the month", yaxis_title="Power Generated in MW")
fig = go.Figure(data = data, layout = layout)
fig.update_layout(
plot_bgcolor=colors['background'],
paper_bgcolor=colors['background'],
font_color=colors['text']
)
app_dash.layout = html.Div(style={'backgroundColor': colors['background']}, children=[
html.H1(
children='Hello George',
style={
'textAlign': 'center',
'color': colors['text']
}
),
html.Div(children='Predicted output from your wind and solar plants', style={
'textAlign': 'center',
'color': colors['text']
})
if __name__ == '__main__':
app_dash.run_server(debug=True)
解决方案
我不是专家,但我知道为此,您必须在代码中将破折号应用程序声明为函数,假设:
def init_dash(server):
dash_app = dash.Dash(
server=server, ...
您可以查看此网站了解更多专业细节。
干杯
推荐阅读
- python-3.x - Sqlalchemy 反射 get_table_names() 缺少表名
- angular - 如何在 Angular 中为单位使用字符串插值
- angular - 文件加载器不适用于角度的动态 url
- react-native - 如何正确对齐同一行中的两个项目
- react-native - 如何通过按 android 硬件后退按钮在本机反应中导航到特定屏幕
- r - R ggplot 标签在非常小的值上被截断
- python - 如何获得最小的非零值
- apache - Apache 代理设置背后的 Icecast - 如何保留原始侦听器 IP
- typo3 - 在 TYPO3 中显示页面的第一个内容元素(掩码元素)
- python - 根据条件从数据框中删除几行