Push Notification in DRF - python

What should be exact and most appropriate method to implement push notifications in django rest framework. DRF documentation doesn't explain it well.
Help me out with this one

Django REST framework is for creating API in django using built in django functionalities to retrieve request and serve response.
Django by itself doesn't support any protocol that will allow push notifications to be sent to client, so DRF also won't do that.
To create push notifications you have to use websockets, there are some third-party packages adding support of websockets to django. One of them is django-websocket-redis

If you are looking for push notification on the web (using web socket), you can try to use Firebase Cloud messaging (FCM, Firebase is free with certain usage threshold). What you need is adding code to your django server to request Firebase to send notifications.
If you are looking for push notifications on mobile devices, django-push-notifications package looks good, it even provide support for DRF to keep track of devices. On Android, this will also use FCM as well.

django-push-notifications is the one you are looking for. It is simple and can be implemented with few lines of code. It can be used for all android, iOS and web push notifications.

If you intend to use WebSocket to implement your own notification, you can check out channels

My Personal Favourite for this Purpose is: Django Notification! And Django Pushy!
Other Packages: django-push-notifications Django Activity Stream
Try using the django-instapush package. It is easily available to install via pip. This support all sql databases and also mongoDB via mongoengine to store device information. It has built-in models that can be used to store device information so this will work out of the box. Here is a little tutorial on sending django push notifications using django instapush.
You can Also use:
https://pypi.org/project/django-sns-mobile-push-notification/
You can also try with some other push providers. Infobip Push has some new things, for example you can track users by their locations and send push whenever they are apporaching some areas

If you project DRF was structured without asynchronous process in mind. You can try out django channels rest framework. you can easily pass asynch classes to you viewsets and make your endpoints behave like an asynchronous porcess.

Related

Verifying in external Django REST API if a Wordpress user is a paid subscriber or not

I have been working on a program in python that I want to make available to paid subscribers via REST. I'm currently thinking of having the frontend made in Wordpress and then host the backend somewhere else.
In wordpress there are a bunch of plugins to handle paid subscribers and so on and everything seems great but my concern is how do I verify this on the backend that is hosted somewhere else?
If I use Django, is there any way I can make some kind of call to the Wordpress server(?) and verify that the user that is trying to fetch items are an paid subscriber?
I made a Diagram to kind of show what I mean. Basically B should only answer back with items if the caller A is a paid subscriber.
I've read that it is possible to generate an API key that will be needed in order to fetch data from the API, I've also read ways of hiding this call from the frontend to the backend from the user by using some kind of relay on wordpress. Might be wrong here.
Is there any preferred way of doing this?
Is Django REST & Wordpress suitable options to do this?
You can do that using the Django REST framework(DRF) which is used for such purpose for making the rest API's.
As per your query i would suggest you to the DRF to read the data from wordpress database and perform the validation on top of it.
Here are some links that you can use for reference :-
https://pythonrepo.com/repo/istrategylabs-django-wordpress-python-third-party-apis-wrappers
https://www.ianlewis.org/en/administer-wordpress-django-admin
In programming almost anything is possible. However, since wordpress is built in php I would not say that it would be possible to work directly with it. But, (MAYBE) you can connect the wordpress database to django for READ only and create an api.
How I would do it if I had this task:
Connect Django to an existing db (your wordpress db):
Django itself teaches you how to connect with a legacy database from its documentation.
Django comes with a utility called inspectdb that can create models by
introspecting an existing database. You can view the output by running
this command:
$ python manage.py inspectdb
Save this as a file by using standard Unix output redirection:
$ python manage.py inspectdb > models.py
**This feature is meant as a shortcut, not as definitive model generation.**
Since you created the models you can create your endpoints:
Create you serializers and viewsets from the models that was auto-generated by django from your wordpress db.
Display the data you need such as the user data you need to fetch ex:paid_subscriber = True or paid_subscriber = 1. Certainly it will be there.
I think the only issue you will have is to connect with the wordpress database. After you have done this in django nothing can stop you to create endpoints with django-rest-framework displaying the data it has.

How to create a Python API and use it with React Native?

I'm learning about basic back-end and server mechanics and how to connect it with the front end of an app. More specifically, I want to create a React Native app and connect it to a database using Python(simply because Python is easy to write and fast). From my research I've determined I'll need to make an API that communicates via HTTP with the server, then use the API with React Native. I'm still confused as to how the API works and how I can integrate it into my React Native front-end, or any front-end that's not Python-based for that matter.
I think you have to follow some online tutorial
And from my experiences, I think Flask is good choice for such case.
This is basic flask tutorial provided by tutorialspoint.com
You have to create a flask proxy, generate JSON endpoints then use fetch or axios to display this data in your react native app. You also have to be more specific next time.

OKTA: Best approach for authenticating users in custom web portal

I'm new to Okta and I'm having a tough time wrapping my head around what I need to do in order to authenticate users.
I'm writing a web portal for a company that already uses Okta internally.
They have requested that I use Okta to authenticate users. That is the only Okta integration requirement.
The portal uses vanilla JS/CSS/HTML5 on the front end, and a custom Python api layer and Python back end for serving data.
I've read through the guide over at http://developer.okta.com/docs/guides/pysaml2.html and I can't help but think this seems like overkill to simply authenticate users.
I saw that when I created a sample app that I could create the app with Secure Web Authentication rather than SAML. Is that advisable in my case? Do we need to use SAML?
If SAML is the correct approach, I'm feeling a bit lost after reading through the documentation about where to even begin. The app itself isn't really a Python app, although Python is used.
I have the Okta app created. I have the custom web app created with a custom Python backend and API layer.
Any tips on how to connect the two in order to authenticate users?
Have you seen this: http://developer.okta.com/docs/guides/okta_sign-in_widget
Seems most appropriate to your situation.

How to send notifications to GCM using python

I'm searching for a way to send push notifications to devices from my django project. I want to send push notifications using pure python, with out third packages like django-gcm or python-gcm.
It is just an HTTP request to an endpoint. The docs explain how to use it. https://developers.google.com/cloud-messaging/downstream

Sockjs - Send message to sockjs-tornado in Python code

I use https://github.com/mrjoes/sockjs-tornado for a Django app. I can send messages from javascript console very easy. But I want to create a signal in Django and send json string once the signal is active.
Could anyone give me a way to send a certain message in Python to sockjs-tornado socket server?
There are few options how to handle it:
Create simple REST API in your Tornado server and post your updates from Django using this API;
Use Redis. Tornado can subscribe to the update key and Django can publish updates to this key when something happens;
Use ZeroMQ (AMQP, etc) to send updates from the Django to the Tornado backend (variation of the 1 and 2).
In most of the cases, it is either first or second option. Some people prefer using 3rd option though.
I've wrote djazator, simple and easy to use django plugin. It uses zeromq for delivering messages from django to sockjs-tornado. Additionally, it can send messages to subset of authenticated django users.
I just put this up https://github.com/amagee/sockjs-client for talking directly to a SockJS server from Python (using xhr streaming).

Categories

Resources