Run Python Script In Django Website When Clicking On Button Submit
I would like to create a button that when launching a python script. This script opens a data.txt file and transforms it into json so that I can integrate it into my database in th
Solution 1:
You should use quotes when using strings with the url template tag:
{% url "recup_wos" %}
It's not clear why you are trying to run a python script using system
. Since it is a Python script it might be better to
from newscript import do_stuff
defrecup_wos(request):
if request.method == 'POST':
do_stuff()
return redirect('../page/accueil')
If that is not possible, then you could use subprocess
instead of os.system
to run the command. If it fails, then you should get a traceback which might help identify the problem.
import subprocess
defrecup_wos(request):
if request.method == 'POST':
subprocess.check_call(['python', 'newscript.py']) # nb lowercase 'python'return redirect('../page/accueil')
Post a Comment for "Run Python Script In Django Website When Clicking On Button Submit"