python - Plotly Dash 与 Django 集成:在侧边栏应用导航时,当前路径welcome.html 与其中任何一个都不匹配
问题描述
我已遵循此视频教程,并成功应用了所有步骤并执行了。它工作正常。我现在正在尝试在侧边栏上添加导航,例如此侧边栏导航菜单底部的表格:但它给出了以下错误:
我的主urls.py如下:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('home.urls')),
path('django_plotly_dash/', include('django_plotly_dash.urls')),
]
我的应用程序urls.py是这样的:
from django import urls
from django.urls import path
from . import views
from home.dash_apps.finished_apps import simpleexample
urlpatterns= [
path('', views.home, name='home'),
path('tables/', views.home1, name='home1')
]
而我的sidebar.html如下:
<li class="nav-item">
<a class="nav-link" href="{% url 'home1' %}">
<i class="fas fa-fw fa-table"></i>
<span>Tables</span></a>
</li>
此外,我在views.py中呈现这个
def home1(request):
def scatter():
x1 = ['PM2.5','PM10','CO2','NH3']
y1 = [30, 35, 25, 45]
trace = go.Scatter(
x=x1,
y = y1
)
layout = dict(
title='Line Chart: Air Quality Parameters',
xaxis=dict(range=[min(x1), max(x1)]),
yaxis = dict(range=[min(y1), max(y1)])
)
fig = go.Figure(data=[trace], layout=layout)
plot_div = plot(fig, output_type='div', include_plotlyjs=False)
return plot_div
context ={
'plot1': scatter()
}
return render(request, 'home/welcome.html', context)
我无法理解如何正确定位welcome.html,以便在我单击仪表板侧栏中的表格时加载它。
解决方案
url 错误,需要按照 URL 定义的 url:
path('', views.home, name='home'),
path('tables/', views.home1, name='home1')
尝试:
172.20.43.46.8001/tables/
推荐阅读
- sql - 根据值选择具有不同别名的列
- python - Pandas 将数据框列中的列表与另一个数据框合并
- javascript - 在模糊事件中将字符串转换为有效 fips 代码的有效方法
- java - Spring-Boot:尝试从 @PostConstruct 方法抛出自定义 RunTimeException 失败
- laravel - 创建或更新行 Laravel
- java - Micronaut 自定义验证约束,根据值编写自定义消息
- python - 无法使用 LBPHFaceRecognizer 和 opencv 训练图像
- mysql - #1241 - 操作数应包含 1 列 SQL 更新
- reactjs - 如何在反应中保护路线?如果管理员登录需要进行身份验证
- amazon-web-services - 仅当 Terraform 中存在文件时才部署资源