Django / Django_plotly_Da sh (значение исключения: ожидаемая строка или байтовоподобный объект) - PullRequest
1 голос
/ 15 апреля 2020

Когда я пытаюсь визуализировать график с помощью Django_Plotly_Da sh, я получаю ошибку TypeError. Смотрите ниже мои фрагменты кода и трассировку, которую я получаю. Я пытался понять, где возникает проблема, но мне в голову не приходит ничего.

simpleexample.py

import dash_core_components as dcc
import dash_html_components as html
from django_plotly_dash import DjangoDash

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = DjangoDash('SimpleExample', external_stylesheets=external_stylesheets)


app.layout = html.Div([
    html.H1('Square Root Slider Graph'),
    dcc.Graph(id='slider-graph', animate=True, style={"backgroundColor": "#1a2d46", 'color': '#ffffff'}),
    dcc.Slider(
        id='slider-updatemode',
        marks={i: '{}'.format(i) for i in range(20)},
        max=20,
        value=2,
        step=1,
        updatemode='drag',
    ),
])

добро пожаловать. html

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

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

views.py

from django.urls import path
from . import views
from home.dash_apps.finished_apps import simpleexample

urlpatterns = [
    path('', views.home, name='home')

Это обратная связь, которую я получаю после размещения приветствия контента. html в базе. html чтобы лучше определить, в чем проблема

  Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/

Django Version: 3.0
Python Version: 3.7.7
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'home.apps.HomeConfig',
 'django_plotly_dash.apps.DjangoPlotlyDashConfig',
 'channels',
 'channels_redis']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']


Template error:
In template C:\Users\milos\statisticsofcorona\templates\base.html, error at line 55
   expected string or bytes-like object
   45 :         <div class="container-fluid">
   46 : 
   47 :           <!-- Page Heading -->
   48 :           <div class="d-sm-flex align-items-center justify-content-between mb-4">
   49 :             <h1 class="h3 mb-0 text-gray-800">Dashboard</h1>
   50 :             <a href="#" class="d-none d-sm-inline-block btn btn-sm btn-primary shadow-sm"><i class="fas fa-download fa-sm text-white-50"></i> Generate Report</a>
   51 :           </div>
   52 :         <div class="row">
   53 :           <div>
   54 :             {% load plotly_dash %}
   55 :              {% plotly_app name="SimpleExample" %} 
   56 :           </div>
   57 :           <div>
   58 :             {{ plot1 | safe }}
   59 :           </div>
   60 :         </div>
   61 : 
   62 : 
   63 :       </div>
   64 :       <!-- End of Main Content -->
   65 : 


Traceback (most recent call last):
  File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django\core\handlers\exception.py", line 34, in inner
    response = get_response(request)
  File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django\core\handlers\base.py", line 115, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django\core\handlers\base.py", line 113, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\milos\statisticsofcorona\home\views.py", line 29, in home
    return render(request, 'base.html', context)
  File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django\shortcuts.py", line 19, in render
    content = loader.render_to_string(template_name, context, request, using=using)
  File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django\template\loader.py", line 62, in render_to_string
    return template.render(context, request)
  File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django\template\backends\django.py", line 61, in render
    return self.template.render(context)
  File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django\template\base.py", line 171, in render
    return self._render(context)
  File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django\template\base.py", line 163, in _render
    return self.nodelist.render(context)
  File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django\template\base.py", line 936, in render
    bit = node.render_annotated(context)
  File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django\template\base.py", line 903, in render_annotated
    return self.render(context)
  File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django\template\library.py", line 214, in render
    _dict = self.func(*resolved_args, **resolved_kwargs)
  File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django_plotly_dash\templatetags\plotly_dash.py", line 76, in plotly_app
    da, app = _locate_daapp(name, slug, da, cache_id=cache_id)
  File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django_plotly_dash\templatetags\plotly_dash.py", line 43, in _locate_daapp
    da, app = DashApp.locate_item(name, stateless=True, cache_id=cache_id)
  File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django_plotly_dash\models.py", line 200, in locate_item
    app = dash_app.as_dash_instance(cache_id=cache_id)
  File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django_plotly_dash\dash_wrapper.py", line 165, in as_dash_instance
    return self.do_form_dash_instance(cache_id=cache_id)
  File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django_plotly_dash\dash_wrapper.py", line 201, in do_form_dash_instance
    return self.form_dash_instance(replacements, ndid, base_pathname)
  File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django_plotly_dash\dash_wrapper.py", line 213, in form_dash_instance
    serve_locally=self._serve_locally)
  File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\django_plotly_dash\dash_wrapper.py", line 312, in __init__
    **kwargs)
  File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\dash\dash.py", line 355, in __init__
    self.init_app()
  File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\dash\dash.py", line 384, in init_app
    @self.server.errorhandler(PreventUpdate)
  File "C:\Users\milos\statisticsofcorona\myvenv\lib\site-packages\dash\exceptions.py", line 6, in __init__
    super(DashException, self).__init__(dedent(msg).strip())
  File "C:\Users\milos\AppData\Local\Programs\Python\Python37\lib\textwrap.py", line 430, in dedent
    text = _whitespace_only_re.sub('', text)

Exception Type: TypeError at /
Exception Value: expected string or bytes-like object
...