Starting a .py file from a Button in my Template

17 views
Skip to first unread message

CooliusCaesar

unread,
Oct 19, 2015, 10:26:51 AM10/19/15
to Django users
Hello,

I need to launch a python file (refresh.py)  from my template.
I have created a .bat wich starts refresh.py, but I can't get it to work:
<button onclick="runbat()"> Launch refresh </button>

<script language="JavaScript" type="text/javascript">  
   
   
MyObject = new ActiveXObject("WScript.Shell");
   
function Runbat()
   
{
       
MyObject.Run("\"C:\\..path...\\refresh.bat\"");
   
}
</script>

Could somebody show me how to "properly" start my refresh.py?
Refresh.py reads log files and checks the status of a few servers. It the deletes the Objects in my SQLite DB and rewrites them.
I would also appreciate if somebody would give me a hint, wich points me in the right direction of how to "properly" solve problems like this in Django.

If you want me to I could upload refresh.py

Thank you in advance!


Andreas Kuhne

unread,
Oct 19, 2015, 10:51:33 AM10/19/15
to django...@googlegroups.com
Hi,

You can't do it that way. If you want to run a python file on the server, you can do it in several ways:

1. Create a view that runs all the code inside the refresh.py file. This could take an amount of time, so I wouldn't do it that way.
2. Create a view that calls a celery task to run the refresh.py file in the background. That way you won't lock the browser while the commands are running.

The way you are trying, you are trying to run the refresh file locally on the client. That will never work (even if you can get it to work in development :-))

Regards,

Andréas

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c43736d0-d1e7-410b-a486-bb9f222bf181%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

CooliusCaesar

unread,
Oct 19, 2015, 11:06:30 AM10/19/15
to Django users

Thank you very much!

I will take a look at celeryproject.org

I should have mentioned, that the project will run on the same computer that is going to display the Servers, so it would work with my refresh.py stored locally. But I will use celery anyways, so I can use this project for future referance
Reply all
Reply to author
Forward
0 new messages