django-plotly-dash serve css files locally

我怕爱的太早我们不能终老 提交于 2021-02-11 13:57:30

问题


I am trying to serve css files locally in a DjangoDash app using django-plotly-dash.

Simpleexample.py

app = DjangoDash('SimpleExample', serve_locally=True)
app.css.append_css("path_to_css")
app.layout = html.Div([
    html.Div(
        className="app-header",
        children=[
            html.Div('Plotly Dash', className="app-header--title")
        ]
    ),
    html.Div(
        children=html.Div([
            html.H5('Overview'),
            html.Div('''
                This is an example of a simple Dash app with
                local, customized CSS.
            ''')
        ])
    )
])

simpleexample.html

{% extends 'base.html' %}
{% load static %}
{% block content %}
{% load plotly_dash %}

    {% plotly_app name='SimpleExample' ratio=0.45 %}
    </div>

{% endblock %}

header.css and topography.css are the files as described here: https://dash.plotly.com/external-resources.

According to these: https://github.com/GibbsConsulting/django-plotly-dash/issues/121 and https://github.com/GibbsConsulting/django-plotly-dash/issues/133, the issues regarding this should be fixed.

However the css styling does not render--

What am I missing here? There was a suggestion in the above github issues that we can use django template rather than iframe. I could not find much documentation on that -- can anyone point me there?

Thank you.


回答1:


<!-- templates/base.html -->
<!DOCTYPE html>
<html>
    <head>
    ...
    {% load plotly_dash%}
    ...
    {% plotly_header %}
    ...
    </head>
    <body>
    ...
    {%plotly_direct name="SimpleExample"%}
    ...
    </body>
    ...
    {% plotly_footer %}
</html>


来源:https://stackoverflow.com/questions/61126537/django-plotly-dash-serve-css-files-locally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!