首页 > 解决方案 > Django 中的 Plotly Dash 应用程序在 __init__() 位置参数上抛出 TypeError

问题描述

我一直在按照这里的例子

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

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

我收到了这个错误

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

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

提前致谢。

标签: pythondjangodashboardplotly-dash

解决方案


阅读此链接,他们建议一种解决方法... https://github.com/GibbsConsulting/django-plotly-dash/issues/290

基本上:

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

这对我有用。

太平洋夏令时。我用 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

推荐阅读