Reputation: 549
I am working on a notification feature in Django, using fcm-django
. I am able to run my code on localhost (development server) but when I deployed the same code to the production server, it's throwing the error:
send_message() missing 1 required positional argument: 'message'
models.py:
class All_Device_Notification(models.Model):
title = models.TextField(default="")
description = models.TextField(default="")
link = models.TextField(default="")
def __str__(self):
return self.title
def save(self, *args, **kwargs):
filtered_users = User.objects.all()
devices = FCMDevice.objects.filter(user__in=list(filtered_users))
devices.send_message(title=self.title, body=self.description, click_action=self.link)
super(All_Device_Notification, self).save(*args, **kwargs)
If I am compiling the code on localhost (development server) and it was working well, then why am I facing the error in the production server?
Upvotes: 2
Views: 1782
Reputation: 43083
You are using fcm-django < 1
on the development server but latest on the production server.
The fix for the issue on the production server is to restrict the version in the requirements file.
requirements.txt:
# fcm-django
fcm-django < 1
You might want to consider Migration to v1.0.
To install the latest version on the development server, run pip install
with the upgrade flag:
pip install -U fcm-django
To downgrade to a lower version:
pip install 'fcm-django<1'
Usage in fcm-django < 1
: https://fcm-django.readthedocs.io/en/archive-pyfcm/
devices.send_message(title=self.title, body=self.description, click_action=self.link)
Usage in the latest version of fcm-django
: https://fcm-django.readthedocs.io/en/latest/
from firebase_admin.messaging import Message, Notification
devices.send_message(
Message(
notification=Notification(title=self.title, body=self.description),
android=AndroidNotification(click_action=self.link),
apns=APNSConfig(payload=APNSPayload(aps=Aps(category=self.link))),
)
)
Upvotes: 2