【问题标题】:Plotly Dash App in Django throws TypeError on __init__() Positional ArgumentsDjango 中的 Plotly Dash 应用程序在 __init__() 位置参数上引发 TypeError
【发布时间】:2021-04-09 10:00:26
【问题描述】:

我一直按照这里的例子进行操作

https://thinkinfi.com/integrate-plotly-dash-in-django/

如果我使用它指定的确切包的包设置虚拟环境,它工作正常。但是我正在尝试遵循此方法并将其实现到现有的 Django 项目中,因此我更愿意使用最新版本的软件包。改用这些版本

  • django-plotly-dash==1.5.0
  • 破折号==1.18.1
  • dash-bootstrap-components==0.11.1
  • dash-daq==0.5.0
  • dpd-static-support==0.0.5
  • 白噪声==5.2.0

我收到了这个错误

Exception inside application: __init__() takes 1 positional argument but 2 were given
Traceback (most recent call last):
  File "/home/jasontam/Personal/GitProjects/dashboard_django/newEnv/lib/python3.8/site-packages/channels/staticfiles.py", line 44, in __call__
    return await self.application(scope, receive, send)
  File "/home/jasontam/Personal/GitProjects/dashboard_django/newEnv/lib/python3.8/site-packages/channels/routing.py", line 71, in __call__
    return await application(scope, receive, send)
  File "/home/jasontam/Personal/GitProjects/dashboard_django/newEnv/lib/python3.8/site-packages/channels/sessions.py", line 47, in __call__
    return await self.inner(dict(scope, cookies=cookies), receive, send)
  File "/home/jasontam/Personal/GitProjects/dashboard_django/newEnv/lib/python3.8/site-packages/channels/sessions.py", line 254, in __call__
    return await self.inner(wrapper.scope, receive, wrapper.send)
  File "/home/jasontam/Personal/GitProjects/dashboard_django/newEnv/lib/python3.8/site-packages/channels/auth.py", line 181, in __call__
    return await super().__call__(scope, receive, send)
  File "/home/jasontam/Personal/GitProjects/dashboard_django/newEnv/lib/python3.8/site-packages/channels/middleware.py", line 26, in __call__
    return await self.inner(scope, receive, send)
  File "/home/jasontam/Personal/GitProjects/dashboard_django/newEnv/lib/python3.8/site-packages/channels/routing.py", line 150, in __call__
    return await application(
  File "/home/jasontam/Personal/GitProjects/dashboard_django/newEnv/lib/python3.8/site-packages/asgiref/compatibility.py", line 33, in new_application
    instance = application(scope)
TypeError: __init__() takes 1 positional argument but 2 were given

有没有人知道如何解决它?我有一个类似的设置很好(除了我无法让它使用像 here 这样的本地 css 文件,并且当我将它预加载到 html teamplate 中时,它与我用于导航和侧边栏,但这是一个不同的问题)我可以比较,并且我已经浏览了 dash_app_code.py 并标记了所有 div 子数组,以防它是差异的地方,但不幸的是不是。

提前致谢。

【问题讨论】:

  • 更新软件包时是否会发生此错误,即使该网站上的相同代码保持不变?或者,您是否在运行不同的代码和更新的依赖项?你必须把事情分解,直到你能找出问题所在。根据版本号的变化,我怀疑它是以下软件包之一:dash-bootstrap-componentsdash-daqdpd-static-support
  • @coralvanda 感谢您的评论。它是在不同包版本上运行的完全相同的代码。我希望这是一件简单而普遍的事情,只有像我这样的菜鸟才会被它困扰
  • 对我来说似乎不是菜鸟问题。也许尝试一次更新一个依赖项并运行以查看它是否有效。继续尝试一个,直到你得到错误。这应该可以帮助您缩小其来源。

标签: python django dashboard plotly-dash


【解决方案1】:

阅读此链接,他们提出了解决方法... https://github.com/GibbsConsulting/django-plotly-dash/issues/290

基本上:

  1. pip install channels_redis
  2. 转到设置文件。
  3. 评论 INSTALLED_APPS 中的“频道”。
  4. 将“channels_redis”添加到 INSTALLED_APPS。

这对我有用。

PDT。 我在 2 个不同的环境中进行了测试,并且在这两个环境中都修复了这个错误。

环境1:

django==4.0
django_plotly_dash==1.6.6
channels==3.0.4
channels_redis==3.3.1
bootstrap4==0.1.0
dpd_static_support==0.0.5
dash==1.20.0
dash_daq==0.5.0
dash_bootstrap_components==0.13.1
pandas==1.3.5
whitenoise==5.3.0

环境 2

django==3.0.5
django_plotly_dash==1.1.4
channels==3.0.4
channels_redis==3.3.1
bootstrap4==0.1.0
dpd_static_support==0.0.5
dash==1.6.1
dash_daq==0.3.1
dash_bootstrap_components==0.7.2
pandas==1.1.5
whitenoise==5.0.1

【讨论】:

    猜你喜欢
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-22
    • 2021-11-09
    • 1970-01-01
    • 2020-08-04
    • 2020-09-25
    相关资源
    最近更新 更多