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 the future.
What I want to do today is just to create a button that when clicking starts the script (I would check in my documents if the file json result.txt has been created which allows me to check if the function works). Here is what I have done:
In urls.py
url(r'whatever^$', views.recup_wos, name='recup_wos'),
In views.py
def recup_wos(request):
if request.method == 'POST':
import newscript.py
os.system('python newscript.py')
return redirect('accueil')
Template accueil.html
<form action='{% url recup_wos %}' method="POST">
<input value="Executer" type="submit">
</form>
The error message is the following:
Reverse for '' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
I think the error is mainly in the view, maybe a syntax error?
I changed my template and my view. It does the redirection well but the script does not launch :
def recup_wos(request):
if request.method == 'POST':
os.system('Python newscript.py')
return redirect('../page/accueil')