$ python manage.py shell
Python 3.6.2 (default, Aug 27 2017, 18:32:19)
[GCC 4.2.1 Compatible Apple LLVM 8.1.0 (clang-802.0.42)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from channels import Group
>>> from github_hook.models import Feed
>>>
>>> Feed.objects.create(name="foo") # Model is created but frontend did not receive any message
>>>
>>> Group("news").send({"text": "dsa"}) # After I do this, a print I had in consumers.py happened
>>> consumers.py is run!
>>>
>>> Feed.objects.create(name="foo") # Now when i created a new object, frontend successfully received the mssage
CHANNEL_LAYERS = { "default": { "BACKEND": "asgi_redis.RedisChannelLayer", "CONFIG": { "hosts": [os.environ.get('REDIS_URL', 'redis://localhost:6379')], }, "ROUTING": "github_hook.routing.channel_routing", },}
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/eafc6aa0-d620-4e2a-af22-a715845fb463%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
#bindings.py
class FeedBinding(WebsocketBinding):
model = Feed stream = "feed" fields = ["__all__"]
@classmethod def group_names(cls, instance): return ["feed-grp", ]
def has_permission(self, user, action, pk): return True
# consumers.py
class Demultiplexer(WebsocketDemultiplexer):
print("consumers.py is run")
consumers = { "feed": FeedBinding.consumer, }
def connection_groups(self):
return ["feed-grp", ]
# routing.pychannel_routing = [ route_class(Demultiplexer, path="^/binding/"),]
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
#apps.py
from django.apps import AppConfig
class HookConfig(AppConfig): name = 'hook_app'
def ready(self): import hook_app.signals # only need to do this for production so that when binding model is created it send out to group # not sure why, question is asked here: https://groups.google.com/forum/#!searchin/django-users/django$20channels|sort:date/django-users/10MPS5RFuAs/TuFI4sqIBAAJ from channels import Group Group("Test")