Django的推送通知与装置自定义模型
我有一个关于Django的推送通知的问题。
I have a question about Django push notifications.
在我的Django项目,我有我的移动设备型号。在这个模型中我有一个令牌(用于发送推送通知),设备平台(iOS或Android)及其他设备信息的所有设备信息。
In my Django project I have my model for mobile device. In this model I have all device info like token (used to send a push notification), device platform (iOS or Android) and other device info.
现在我已经实现逻辑对于这些推送通知的发送和我会使用像某些库Django的推通知的。
Now I have implement the logic for sending of these push notifications and I would to use some library like django-push-notifications.
我已阅读文档和我意识到,这个库中已经在内部使用的模型相对于设备:GCMDevice或APNSDevice
I have read the documentation and I realized that this library already uses internally a model with respect to devices: GCMDevice or APNSDevice.
我如何使用Django推通知我的设备型号?是否有一个整洁的方式做到这一点?
How can I use django-push-notification with my device model? Is there a neat way to do this?
做完所有的工作时,你也许并不需要一个库,可以通过简单的HTTP岗位到GCM服务器发送GCM的消息,这只是一个code的几行。如果您使用的是蟒蛇请求库已经针对HTTP的东西,它实际上是一个单行
Having done all that work, you probably don't need a library, you can send your GCM messages by making simple HTTP posts to the GCM server it's only a few lines of code. If you are using the python requests library already for http stuff, it's practically a one liner.
requests.post( 'https://gcm-http.googleapis.com/gcm/send',
data = json.dumps(message),
headers = {'Authorization': auth_token,'Content-Type': 'application/json'})
其中,消息是这是继 GCM文档的指导方针和看起来像你的GCM消息这个。
Where message is your GCM message which follows the guidelines on GCM docs and looks like this.
{ "notification": {
"title": "Portugal vs. Denmark",
"text": "5 to 1"
},
"to" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx..."
}
的auth_token
看起来像键= YOUR_GCM_KEY
auth_token
will look like 'key=YOUR_GCM_KEY'
最后,如果你真的热衷于使用更复杂的库,但要preserve你的模型,考虑的 Python的GCM 它可以很容易地插入到Django的。
Lastly if you are really keen to use a more complex library but want to preserve your models, consider Python GCM which can be plugged into django quite easily.