[Answer]-How to invoke a python script after successfully running a Django view

1👍

Runing a script from the javascript is not a clean way to do it, because the user can close the browser, disable js … etc. instead you can use django-celery, it let you run backgroud scripts and you can check to status of the script dynamically from a middleware. Good luck

0👍

You could add a client-side timeout to AJAX back to the server 10-15 sec later. Point it to a different view and execute your script within that view. For example:

function runServerScript() {
    $.get("/yourviewurlhere", function(data) {
        // Do something with the return data
    });
}
setTimeout("runServerScript()", 10000);

If you want status to be displayed, the client would have to make multiple requests back to the server.

👤Scotty

0👍

Celery might come in handy for such use cases. You can start a task (or script as you call them) from a view (even with a delay, as you want). Sending status reports back to the browser will be harder unless you opt for something like WebSockets but that’s highly experimental right now.

Leave a comment