问题
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