本文介绍了django-plotly-dash在本地提供CSS文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用django-plotly-dash在DjangoDash应用中本地提供css文件.

Simpleexample.py

  app = DjangoDash('SimpleExample',serve_locally = True)app.css.append_css("path_to_css")app.layout = html.Div([html.Div(className ="app-header",孩子们= [html.Div('Plotly Dash',className ="app-header--title")]),html.Div(children = html.Div([html.H5('概述'),html.Div('''这是一个简单的Dash应用程序的示例,其中包含本地定制的CSS.''')]))]) 

simpleexample.html

  {%扩展了'base.html'%}{%静态负载%}{%封锁内容%}{%load plotly_dash%}{%plotly_app name ='SimpleExample'ratio = 0.45%}</div>{%endblock%} 

header.css和topography.css是此处描述的文件:

我在这里想念什么?在上面的github问题中,有人建议我们可以使用django模板而不是iframe.我找不到关于它的太多文档-谁能指出我的意思?

谢谢.

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

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.

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

这篇关于django-plotly-dash在本地提供CSS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 08:00
查看更多