【问题标题】:Django plotly dash-application returning completely blank page when using django bootstrap components使用 django bootstrap 组件时,Django plotly dash-application 返回完全空白页面
【发布时间】:2020-07-30 05:05:37
【问题描述】:

我正在使用 Django 和 Dash 以及出色的 django_plotly_dash 包构建一个 Web 应用程序。一切都运行顺利,除了当我尝试包含 Django 引导组件时。即使添加单个 Django 引导组件也会导致页面完全空白 - 甚至来自 django_plotly_dash 的 html-div 也会消失。此外,external_stylesheets 选项似乎完全被忽略了,即使在add_bootstrap_links=True 时也是如此。

这会产生预期的输出:

import dash_html_components as html
from django_plotly_dash import DjangoDash
import dash_bootstrap_components as dbc

dis = DjangoDash("test_app_dash",
                 add_bootstrap_links=True)

dis.layout = html.Div(
    [
        html.H1("THIS WORKS FINE"),        
    ]
)

虽然这会产生一个完全空白的页面(没有引发任何异常):

import dash_html_components as html
from django_plotly_dash import DjangoDash
import dash_bootstrap_components as dbc

dis = DjangoDash("test_app_dash",
                 add_bootstrap_links=True)

dis.layout = html.Div(
    [
        html.H1("THIS WORKS FINE"),
        dbc.Alert("THIS DOES NOT WORK", id="base-alert", color="primary"),    
    ]
)

以下是一个最小工作示例的一些关键文件(请参阅screenshot of full project structure):

test_app views.py:

from django.shortcuts import render 
from . import test_app_dash

def test(request):
    return render(request, "test_app/test.html")

主 urls.py:

from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path("", include("test_app.urls")),
    path('admin/', admin.site.urls),
    path('django_plotly_dash/', include('django_plotly_dash.urls'))
]

test_app urls.py:

from django.urls import path
from . import views as test_views

urlpatterns = [
    path("", test_views.test, name = "test")
]

来自settings.py的sn-p:

INSTALLED_APPS = [
    'django_plotly_dash.apps.DjangoPlotlyDashConfig',
    'channels',
...]

...
CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'channels_redis.core.RedisChannelLayer',
        'CONFIG': {
            'hosts': [('127.0.0.1', 6379),],
        },
    },
}

X_FRAME_OPTIONS = 'SAMEORIGIN'

ASGI_APPLICATION = "test_app.routing.application"

test.html:

{% load plotly_dash %}

{% plotly_app name="test_app_dash" %}

如果有人能对此有所了解,那就太好了!我难住了。如果您需要更多信息,请告诉我。

【问题讨论】:

    标签: python django bootstrap-4 plotly-dash


    【解决方案1】:

    在 test.html 中将 plotly_app 更改为 plotly_app_bootstrap

    【讨论】:

      猜你喜欢
      • 2022-07-01
      • 1970-01-01
      • 2022-11-19
      • 2019-08-22
      • 2021-04-15
      • 2022-10-06
      • 2021-01-07
      • 2020-09-21
      • 2019-01-04
      相关资源
      最近更新 更多