简体   繁体   English

使用 Django Rest 框架 jwt 身份验证实现通知

[英]Implementing notifications with Django Rest Framework jwt authentication

I have developed an android app which uses Django rest framework as backend with JWT Authentication.我开发了一个 android 应用程序,它使用 Django rest 框架作为后端,使用 Z1D1FADBD9150349C135ZAuthentication.

Now I want to add notification service to it.现在我想向它添加通知服务。 There are many notification service providers like firebase cloud message and azure notification centre.有许多通知服务提供商,如firebase云消息和azure通知中心。

I need some guidance to implement this我需要一些指导来实现这一点

Like, this is my user profile model:就像,这是我的用户配置文件 model:

class UserProfile(models.Model):
    user = models.OneToOneField(User, on_delete = models.CASCADE)
    is_teacher = models.BooleanField(default= False)

and I only want to send a notification to the users who are logged in as teacher .我只想向以教师身份登录的用户发送通知

For notifications in my app i was using Firebase.对于我的应用程序中的通知,我使用的是 Firebase。 There is realy nice library for connecting it to django.有一个非常好的库可以将它连接到 django。 If you wanna send notifications only to teachers, you can do it in bulk like in this example :如果您只想向教师发送通知,您可以像 以下示例中那样批量发送:

from fcm_django.models import FCMDevice

devices = FCMDevice.objects.all()

devices.send_message(title="Title", body="Message")
devices.send_message(title="Title", body="Message", data={"test": "test"})
devices.send_message(data={"test": "test"})

Just change FCMDevice.objects.all() to set of devices connected to teachers.只需将FCMDevice.objects.all()更改为连接到教师的设备集。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM