Communication between django and external script

Hi guys,

I don’t know if this is in the right place but I have a question. I have a script that reads nfc/frid tags on a raspberry pi and stores it in the database.
Now I need to create an application that allows me to graphically see who passed the tag etc so I’d like to hear opinions on how I’m going to communicate between the script and a django server or flask etc.

You mention that you’re already writing the values to the database. Django can read that database to retrieve the data.

What sort of communication do you need between the script and Django?

The database will be shared yes,
The use case is: When a user passes the tag we see on the screen who passed the tag. The django need to receive or know who tagged the reader. for example.

If the server receive the tag id, i can use websockets to push the data to the frontend, but the server needs to receive the data and know there is new data to show

Since you’re using websockets, you have at least two options.

  • You could set up a URL in Django that the Pi can access (perhaps using requests) to signal that new data has been written. (Depending upon what data you have and need, you could even send the data in the request.)

  • You could have the Pi open a websocket (as a client) with the server instance of Channels and pass the notification (and possibly the data) through a websocket frame.

The django server will live inside the Pi.

I can use the channels on the script? good to know, i will explore that

And use something like celery a rabbitmq?

For what purpose? (I don’t see where this fits into what you’ve described so far)

To clarify:

I’m assuming that this “script” is a separate Python program. If so, then it would be running a websocket client, not Channels. That websocket client would be opening a connection to your Django/Channels server.

yes it is a different program. i am exploring solutions. and mqtt instead of websokets?

Ick. If you’re running Django/Channels for websocket support, you’ll already be using redis. There’s no reason to add an additional process into the mix.

If you don’t want to create a websocket client and don’t want to use a standard URL as a “trigger”, a far better solution would be to create your script as an external Channels Worker process and allow your external script to send the message through redis directly to the consumer.


I´m not using anything so far. i have only the script reading data and store in the database. I´m searching and try to figure how to do this in a good way.

And if the script live inside Django? or its not a good idea?

Physically, it’s fine for the script to be placed within your Django directory structure. But since it needs to run independently of Django as an always-running task, it won’t be running in the same process as your Django process.