Abdessalem Letaief
Abdessalem Letaief

Reputation: 155

How to integrate a python script to run when starting a Django project

I'm working on a platform that uses Django and Django REST Framework, so this platform is used to monitor the state of some sensors which send data to the computer.

Now I have the data in the computer, and I want to create a Python file to read the data from the computer and store it in a MySQL database that Django will read and show to the user.

I have two questions:

Upvotes: 0

Views: 164

Answers (2)

m3lhIN400Forty4
m3lhIN400Forty4

Reputation: 37

You could also use this https://github.com/kraiz/django-crontab

That makes it even more simple to use

Upvotes: 1

The Pjot
The Pjot

Reputation: 1859

Can i make django read from the file save the data in the database

Yes, you could create a management command for this which could be run from crontab. Or create a sort of 'daemonized' version which keep on running but sleeps for X amount of seconds before running again. This command reads the data, puts it into the database.

show it in the user interface ?

Yes, but I would advise against doing this sequential (as in, don't put your 'data reading' in your view!!). So your managment command updates the database with the latest data and you view only shows the latest data.

Upvotes: 2

Related Questions