简体   繁体   English

Django Rest 框架中的 django-push-notifications

[英]django-push-notifications in Django Rest Framework

I'm trying to use django-push-notifications library in my Django REST backend project.我正在尝试在我的 Django REST 后端项目中使用django-push-notifications库。 I have used Firebase Cloud Messaging.我使用过 Firebase 云消息传递。 Here is the implementation;这是实现;

settings.py设置.py

PUSH_NOTIFICATIONS_SETTINGS = {
    "FCM_API_KEY": "private key from FCM app"
}

views.py视图.py

user, created = User.objects.get_or_create(email=email, username=username)

if created:
    GCMDevice.objects.create(registration_id="token", cloud_message_type="FCM", user=user)

models.py模型.py

@receiver(post_save, sender=Action)
def create_new_action(sender, instance, created, **kwargs):
    if created:
        devices = GCMDevice.objects.filter(Q(user=instance.admin)|Q(user__in=instance.users.all()))
        msg = "New action is created in %s" % instance.name
        devices.send_message(msg)

My question is what should registration_id be while I'm creating the GCMDevice object for each registered user?我的问题是,当我为每个注册用户创建 GCMDevice 对象时, registration_id应该是什么?

registration_id come from your frontend registration_id来自您的前端

actually you must have an api that get user(frontend) fcm token or get it(fcm token) in user registration or login api's实际上,您必须有一个 api 来获取用户(前端)fcm 令牌或在用户注册或登录 api 中获取它(fcm 令牌)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Apple推送通知不适用于带有django-push-notifications的生产环境 - Apple Push Notifications are not working in production with django-push-notifications 使用django-push-notifications库将django推送通知到android - django push notification to android using django-push-notifications library Django多模型继承,django-push-notifications - Django multiple model inheritance, django-push-notifications 哪个更好:fcm-django或django-push-notifications? - Which is better: fcm-django or django-push-notifications? 如何使用带有 APNS.p8 证书的 django-push-notifications - How to use django-push-notifications with an APNS .p8 certificate Django REST框架getstream通知 - Django REST framework getstream notifications 使用带有 Django-Push-Notifications 的 Firebase 云消息传递时,如何使用 TTL 来防止消息积压? - How can I use TTL to prevent a message backlog when using Firebase Cloud Messaging with Django-Push-Notifications? 使用 Django Rest 框架 jwt 身份验证实现通知 - Implementing notifications with Django Rest Framework jwt authentication 龙卷风,Django和推送通知 - Tornado, Django, and push notifications 使用 Django 的浏览器推送通知 - Browser push notifications with Django
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM