我升级到 Django 4.2.1,django_plotly_dash 不再工作 - WrappedDash 对象没有属性 _generate_meta_html

问题描述 投票:0回答:1

django_plotly_dash 文档说它们现在与 5x > Django > 3.2x 兼容,但是将 Django 升级到 4.2.1 后,我只能使其在本地工作,但在生产中返回我在下面分享的回溯。

设置.PY

INSTALLED_APPS = [
    ...

    'django_plotly_dash.apps.DjangoPlotlyDashConfig',
    'dpd_static_support',
    'channels', 
    'channels_redis'
    ...
]

PLOTLY_COMPONENTS = [
    'dash_core_components',
    'dash_html_components',
    'dash_renderer',
    'dpd_static_support',
    'dpd_components',
    'dash_bootstrap_components',
]

X_FRAME_OPTIONS = 'SAMEORIGIN'

PLOTLY_DASH = {

    "ws_route" :   "dpd/ws/channel",
    "http_route" : "dpd/views",
    "http_poke_enabled" : True,
    "insert_demo_migrations" : False,
    "cache_timeout_initial_arguments": 60,
    "view_decorator": None,
    "cache_arguments": True,
    "serve_locally": False,
}

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

ASGI_APPLICATION = 'core.asgi.application' #Also tried using my custom routing

路由.PY

from django_plotly_dash.routing import application

URLS.PY

from app import custom_dash_app

urlpatterns = [
...
path('django_plotly_dash/', include('django_plotly_dash.urls')),
...
]

HTML

{% load plotly_dash %}

...
{% plotly_app_bootstrap name="custom_dash_app_name" aspect="16by9" %} <-- Also tried with direct and with plotly_app  name="" ratio=... -->
...


Traceback (most recent call last):
web_container |   File "/usr/local/lib/python3.10/site-packages/asgiref/sync.py", line 486, in thread_handler
web_container |     raise exc_info[1]
web_container |   File "/usr/local/lib/python3.10/site-packages/django/core/handlers/exception.py", line 42, in inner
web_container |     response = await get_response(request)
web_container |   File "/usr/local/lib/python3.10/site-packages/django/core/handlers/base.py", line 253, in _get_response_async
web_container |     response = await wrapped_callback(
web_container |   File "/usr/local/lib/python3.10/site-packages/asgiref/sync.py", line 448, in __call__
web_container |     ret = await asyncio.wait_for(future, timeout=None)
web_container |   File "/usr/local/lib/python3.10/asyncio/tasks.py", line 408, in wait_for
web_container |     return await fut
web_container |   File "/usr/local/lib/python3.10/site-packages/asgiref/current_thread_executor.py", line 22, in run
web_container |     result = self.fn(*self.args, **self.kwargs)
web_container |   File "/usr/local/lib/python3.10/site-packages/asgiref/sync.py", line 490, in thread_handler
web_container |     return func(*args, **kwargs)
web_container |   File "/aiterra_web_website/wallet/views.py", line 46, in walletHomepage
web_container |     return render(request, 'investing/wallet-homepage.html', context)
web_container |   File "/usr/local/lib/python3.10/site-packages/django/shortcuts.py", line 24, in render
web_container |     content = loader.render_to_string(template_name, context, request, using=using)
web_container |   File "/usr/local/lib/python3.10/site-packages/django/template/loader.py", line 62, in render_to_string
web_container |     return template.render(context, request)
web_container |   File "/usr/local/lib/python3.10/site-packages/django/template/backends/django.py", line 61, in render
web_container |     return self.template.render(context)
web_container |   File "/usr/local/lib/python3.10/site-packages/django/template/base.py", line 175, in render
web_container |     return self._render(context)
web_container |   File "/usr/local/lib/python3.10/site-packages/django/template/base.py", line 167, in _render
web_container |     return self.nodelist.render(context)
web_container |   File "/usr/local/lib/python3.10/site-packages/django/template/base.py", line 1005, in render
web_container |     return SafeString("".join([node.render_annotated(context) for node in self]))
web_container |   File "/usr/local/lib/python3.10/site-packages/django/template/base.py", line 1005, in <listcomp>
web_container |     return SafeString("".join([node.render_annotated(context) for node in self]))
web_container |   File "/usr/local/lib/python3.10/site-packages/django/template/base.py", line 966, in render_annotated
web_container |     return self.render(context)
web_container |   File "/usr/local/lib/python3.10/site-packages/django/template/loader_tags.py", line 157, in render
web_container |     return compiled_parent._render(context)
web_container |   File "/usr/local/lib/python3.10/site-packages/django/template/base.py", line 167, in _render
web_container |     return self.nodelist.render(context)
web_container |   File "/usr/local/lib/python3.10/site-packages/django/template/base.py", line 1005, in render
web_container |     return SafeString("".join([node.render_annotated(context) for node in self]))
web_container |   File "/usr/local/lib/python3.10/site-packages/django/template/base.py", line 1005, in <listcomp>
web_container |     return SafeString("".join([node.render_annotated(context) for node in self]))
web_container |   File "/usr/local/lib/python3.10/site-packages/django/template/base.py", line 966, in render_annotated
web_container |     return self.render(context)
web_container |   File "/usr/local/lib/python3.10/site-packages/django/template/loader_tags.py", line 63, in render
web_container |     result = block.nodelist.render(context)
web_container |   File "/usr/local/lib/python3.10/site-packages/django/template/base.py", line 1005, in render
web_container |     return SafeString("".join([node.render_annotated(context) for node in self]))
web_container |   File "/usr/local/lib/python3.10/site-packages/django/template/base.py", line 1005, in <listcomp>
web_container |     return SafeString("".join([node.render_annotated(context) for node in self]))
web_container |   File "/usr/local/lib/python3.10/site-packages/django/template/base.py", line 966, in render_annotated
web_container |     return self.render(context)
web_container |   File "/usr/local/lib/python3.10/site-packages/django/template/library.py", line 258, in render
web_container |     _dict = self.func(*resolved_args, **resolved_kwargs)
web_container |   File "/usr/local/lib/python3.10/site-packages/django_plotly_dash/templatetags/plotly_dash.py", line 149, in plotly_direct
web_container |     resp = view_func()
web_container |   File "/usr/local/lib/python3.10/site-packages/django_plotly_dash/dash_wrapper.py", line 762, in index
web_container |     metas = self._generate_meta_html()
web_container | AttributeError: 'WrappedDash' object has no attribute '_generate_meta_html'

我已经尝试将 python 升级到最新且稳定的版本,但没有成功。

我设法在这里找到包装器的东西:https://github.com/GibbsConsulting/django-plotly-dash/blob/master/django_plotly_dash/dash_wrapper.py

_generate_meta_html 似乎是问题所在......但到目前为止不知道如何解决这个问题。

def index(self, *args, **kwargs):  # pylint: disable=unused-argument
        scripts = self._generate_scripts_html()
        css = self._generate_css_dist_html()
        config = self._generate_config_html()
        metas = self._generate_meta_html()
        renderer = self._generate_renderer()
        title = getattr(self, 'title', 'Dash')
        if self._favicon:
            import flask
            favicon = '<link rel="icon" type="image/x-icon" href="{}">'.format(
                flask.url_for('assets.static', filename=self._favicon))
        else:
            favicon = ''

            _app_entry = '''
            <div id="react-entry-point">
                <div class="_dash-loading">
                   Loading...
                </div>
            </div>
        '''
        index = self.interpolate_index(
            metas=metas, title=title, css=css, config=config,
            scripts=scripts, app_entry=_app_entry, favicon=favicon,
            renderer=renderer)

        return index
django docker plotly-dash
1个回答
0
投票

我也有类似的问题:

  • python 3.11
  • Django 3.2.20
  • 破折号2.11.1
  • django-plotly-dash 2.2.2
django                    | Traceback (most recent call last):
django                    |   File "/home/app/.venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 47, in inner
django                    |     response = get_response(request)
django                    |                ^^^^^^^^^^^^^^^^^^^^^
django                    |   File "/home/app/.venv/lib/python3.11/site-packages/django/core/handlers/base.py", line 181, in _get_response
django                    |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
django                    |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django                    |   File "/home/app/app/eda_app/view_decorator.py", line 141, in wrapped_view
django                    |     return view_function(request, *args, **kwargs)
django                    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django                    |   File "/home/app/.venv/lib/python3.11/site-packages/django_plotly_dash/views.py", line 115, in main_view
django                    |     resp = view_func()
django                    |            ^^^^^^^^^^^
django                    |   File "/home/app/.venv/lib/python3.11/site-packages/django_plotly_dash/dash_wrapper.py", line 762, in index
django                    |     metas = self._generate_meta_html()
django                    |             ^^^^^^^^^^^^^^^^^^^^^^^^
django                    | AttributeError: 'WrappedDash' object has no attribute '_generate_meta_html'

问题是

dash
在版本
_generate_meta_html
中没有
>2.10
方法(例如参见v2.9.3v.2.10.0)。

甚至在 django-plotly-dash 项目的

setup.py
中提到不支持这样的版本(但在我这边使用包版本管理器并未将其标记为依赖冲突)。

解决方案

  • 安装
    dash>=2.0,<2.10

我希望它有帮助:)

© www.soinside.com 2019 - 2024. All rights reserved.