Django中的Plotly Dash应用程序在__init__()位置参数上抛出TypeError



我一直在遵循的示例

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

如果我用它指定的确切包的包来设置虚拟环境,它就可以正常工作。然而,我正试图遵循这种方法,并将其实现到现有的Django项目中,所以我更喜欢使用最新版本的包。用这些版本代替

  • django plotly dash==1.5.0
  • 破折号==1.18.1
  • 仪表板引导组件==0.11.1
  • dash-daq==0.5.0
  • dpd静态支撑==0.0.5
  • whiteoise==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

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

提前谢谢。

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

基本上:

  1. pip install channels_redis
  2. 转到设置文件
  3. 对INSTALLED_APPS中的"通道"进行注释
  4. 将"channels_redis"添加到INSTALLED_APPS

这对我有效。

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

环境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

最新更新