Hello there. I'm working on the Channels library for the first time and testing the 2.1.6 version of your channels documentation (dated 09 December 2018).
However, even though I do all the steps step by step, I get the following error when I apply the following line on page 21.
mesut@ubuntu:~/Desktop/Django_Channels_Tutorial/mysite$ sudo python3 manage.py shell
[sudo] password for mesut:
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import channels.layers
>>> channel_layer = channels.layers.get_channel_layer()
>>> from asgiref.sync import async_to_sync
>>> async_to_sync(channel_layer.send)('test_channel', {'type':'hello'})
Traceback (most recent call last):
File "/usr/lib/python3.6/code.py", line 91, in runcode
exec(code, self.locals)
File "<console>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'send'
>>> type(channel_layer)
<class 'NoneType'>
>>>
And my settings.py config related lines like that:
ASGI_APPLICATION = 'mysite.routing.application'
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
"hosts": [('127.0.0.1', 6379)],
},
},
}
Why am I getting this error and how do I fix it?
Thank you in advance for those who will help.
I solved the problem. The problem is that the configuration of the CHANNEL_LAYERS configuration should not be saved even though settings.py was visible on the ubuntu virtual machine. I solved it by rebooting the virtual machine.
I just have met that problems, your solution is right for me
A good way to test for such issues:
from django.conf import settings
settings.CHANNEL_LAYERS
If you get "AttributeError: 'Settings' object has no attribute 'CHANNEL_LAYERS'" the system is not reading your settings file - or rather not up to date.
Most helpful comment
I solved the problem. The problem is that the configuration of the CHANNEL_LAYERS configuration should not be saved even though settings.py was visible on the ubuntu virtual machine. I solved it by rebooting the virtual machine.