diff --git a/apps/back/consumers.py b/apps/back/consumers.py index 71cd5cb..724a729 100644 --- a/apps/back/consumers.py +++ b/apps/back/consumers.py @@ -1,11 +1,12 @@ import json -from channels.generic.websocket import AsyncWebsocketConsumer +from channels.generic.websocket import WebsocketConsumer +from django.template.loader import render_to_string -class BlogConsumer(AsyncWebsocketConsumer): +class BlogConsumer(WebsocketConsumer): def connect(self): ''' Cliente se conecta ''' - + print('cooooooooooooonectando') # Recoge el nombre de la sala self.room_name = self.scope["url_route"]["kwargs"]["room_name"] self.room_group_name = "blog_%s" % self.room_name @@ -16,6 +17,17 @@ class BlogConsumer(AsyncWebsocketConsumer): # Informa al cliente del éxito self.accept() + # Send message to WebSocket + self.send( + text_data=json.dumps( + { + "selector": "#articles", + "position": "appendChild", + "html": render_to_string('blog/articles.html', {'pag': 1}) + } + ) + ) + def disconnect(self, close_code): ''' Cliente se desconecta ''' # Leave room group diff --git a/apps/front/templates/blog.html b/apps/front/templates/blog.html deleted file mode 100644 index 2c2273c..0000000 --- a/apps/front/templates/blog.html +++ /dev/null @@ -1,125 +0,0 @@ - - -
- -