I have a project in django 2.0 nad django-channlels 2.0 which I need to host I followed the documentation and I was able to run channels on localhost along with redis but when I hosted on pythonanywhere,it showed it doesnot support websocket, so then I hosted on heroku,but there they were asking for verification of credit card info which i dont have to run redis.Are there additional hosting website whre I can rrun redis erver for free
Or is it poosible to implement channels without channel_layer and redis.My code is working perfectly fine on local host but can't host online for free.
class PageConsumer(WebsocketConsumer):
def connect(self, **kwargs):
self.accept()
channel_layer = get_channel_layer()
async_to_sync(channel_layer.group_send)("admin", {"type": "analytics.admin_message", "message": "plus"})
def disconnect(self, close_code):
channel_layer = get_channel_layer()
async_to_sync(channel_layer.group_send)("admin", {"type": "analytics.admin_message", "message": "minus"})
its corresponidng receiver
class ChatConsumer(WebsocketConsumer):
def connect(self, **kwargs):
self.accept()
async_to_sync(self.channel_layer.group_add)("admin", self.channel_name)
def disconnect(self, close_code):
async_to_sync(self.channel_layer.group_discard)("admin", self.channel_name)
def analytics_admin_message(self, something):
if something["message"] == "plus":
self.send(text_data=json.dumps({
'message': "plus"
}))
else:
self.send(text_data=json.dumps({
'message': "minus"
}))
def receive(self, text_data):
print("data hai bhyi", text_data)
text_data_json = json.loads(text_data)
message = text_data_json['message']
self.send(text_data=json.dumps({
'message': message
}))
settings.py
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [("127.0.0.1", 6379)],
},
},
}