【问题标题】:module 'mysite.asgi' has no attribute 'channel_layer' on Heroku and Django application模块“mysite.asgi”在 Heroku 和 Django 应用程序上没有属性“channel_layer”
【发布时间】:2020-04-13 08:49:09
【问题描述】:

我正在尝试将 Django 应用程序部署到 Heroku,但我不断收到以下错误:

2020-04-13T08:45:00.134349+00:00 app[web.1]: Traceback (most recent call last):
2020-04-13T08:45:00.134389+00:00 app[web.1]:   File "/app/.heroku/python/bin/daphne", line 8, in <module>
2020-04-13T08:45:00.134519+00:00 app[web.1]:     sys.exit(CommandLineInterface.entrypoint())
2020-04-13T08:45:00.134524+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/daphne/cli.py", line 191, in entrypoint
2020-04-13T08:45:00.134697+00:00 app[web.1]:     cls().run(sys.argv[1:])
2020-04-13T08:45:00.134699+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/daphne/cli.py", line 252, in run
2020-04-13T08:45:00.134891+00:00 app[web.1]:     application = import_by_path(args.application)
2020-04-13T08:45:00.134913+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/daphne/utils.py", line 14, in import_by_path
2020-04-13T08:45:00.135028+00:00 app[web.1]:     target = getattr(target, bit)
2020-04-13T08:45:00.135056+00:00 app[web.1]: AttributeError: module 'mysite.asgi' has no attribute 'channel_layer

这是我的 Procfile:

web: daphne WR.asgi:channel_layer --port $PORT --bind 0.0.0.0 -v2

这是我在 settings.py 上定义 Redis 的方式:

CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'channels_redis.core.RedisChannelLayer',
        'CONFIG': {
            "hosts": [('https://mytestapp1.herokuapp.com/', 6379)],
            'capacity': 1500,
            'expiry': 2,
        },
    },
}

谁能帮我找出我做错了什么?难道是我必须将 Redis heroku 插件添加到我的应用程序中吗?

【问题讨论】:

    标签: python django heroku django-channels


    【解决方案1】:

    看到 asgi.py 会很好,但我想这会有所帮助。

    web: daphne WR.asgi:应用程序 --port $PORT --bind 0.0.0.0 -v2

    【讨论】:

      猜你喜欢
      • 2021-03-29
      • 2011-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-19
      • 2011-09-18
      • 2015-06-02
      相关资源
      最近更新 更多