Python Forum
Controlling Python Program From Django Front End - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Controlling Python Program From Django Front End (/thread-10429.html)



Controlling Python Program From Django Front End - sourabhjaiswal92 - May-20-2018

Hi,

I am working on a project for which I have written the back end in python socket programming an multi threading. For the same project I am writing Django based website now.

My requirement is I need to control the back end script from django website. What the back end script does is.. it does telnet to some network elements fires some commands and get the relevant data which is further stored in a sqlite db created for each run.

Now I was thinking of overloading system interrupts in the back end script like SIGTERM and all. After that from django start the script and save its PID. Further to send signals to that script django will send system interrupts(Overloaded in back end script) to that PID. Based on which the back end script will do some action.

The problem what I am seeing in this approach is, its one way communication. If any error, for example if login to network element failed in back end script. There is no way for django to know that.

Sorry for so much text. But I needed to explain my understanding.

Can anyone please guide me right direction. I am very new to django and python and short on time to complete this project.

Thanks a lot in advance.

Regards, Jaiswal


RE: Controlling Python Program From Django Front End - wavic - May-20-2018

Hello. You can establish some kind of secure connection between the script and the website. Both can communicate using JSON to each other. For example. You can easily send commands which the script can understand and get back the output.


RE: Controlling Python Program From Django Front End - sourabhjaiswal92 - May-21-2018

Hi,
Thanks for the reply.

But I am new to this type of communication and I have not worked on JSON.
Can you please explain a bit.
I tried googling what you suggested but dint find anything helpful.

Regards,
Jaiswal


RE: Controlling Python Program From Django Front End - wavic - May-21-2018

Just like any other program, this one could listen to a port for a connection from the website for some message which can be interpreted as a command. After that, it does its things and returns a response back to the website which you can see.
JSON stands for JavaScript Object Notation. Perhaps every programming language can deal with it. It has a simple structure, it's human-readable and consists of key-value pairs. It looks like this:

"person" {
    "first": "Donald",
    "last": "Trump",
    "characteristics": ["president of the USA", "businessman"]
    }
The messages could be a simple text too. It depends on what suits your needs.