I have a DJANGO app (kwtest) that has VIEWS(a+b) and associated URL(s). When I access the first kw_dash (kw_dash.html) URL and press a button it calls a python script (from import) and should return this to the "return_results" (script_return.html) URL. The functionality is working fine but the output is "none" in the browser for "return_results". The script is also continuous and I can only stop by killing the SSH session (at the moment). I have searched for a while for the results and am after guidance (I am new to this). Any help much appreciated.
The script is working fine in console.
kw_dash.html;
{% load staticfiles %}
<html>
<body>
<div class=”button”>
<a href={% url 'kwtest:remote_results' %}>Run_Results</a>
</div>
</body>
</html>
script_return.html;
<html>
<head>
<title>Remote Results</title>
</head>
<body>
<div>
<pre>{{ output }}</pre>
</div>
</body>
</html>
viewa;
from django.shortcuts import render
def kw_dash(request):
return render(request, 'kwtest/kw_dash.html', {})
viewb;
#- * -coding: utf - 8 - * -
from django.shortcuts import render
from django.http import HttpResponse
from django.http import HttpResponseRedirect
import remote_results
def remote_results(request):
import remote_results
output = remote_results.remote_results()
return render(request, 'kwtest/script_results.html', {
'output': output
})
remote_results.py;
import paramiko
def remote_results():
hostname ='192.168.xx.xx'
port = 22
username='xxxxxx'
pkey_file = '/home/test/.ssh/id_rsa'
key = paramiko.RSAKey.from_private_key_file(pkey_file)
s = paramiko.SSHClient()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
s.connect(hostname, port, pkey=key)
stdin, stdout, stderr = s.exec_command('cd /root/xxxxx/xxxx/ ; python xxxxx.py', get_pty=True)
print stdout.read()
s.close()
if __name__=="__main__":
remote_results()
The actual result should be the continuous results of the xxxxx.py in the correct url, currently when I force the script to stop the url then returns "none".
The xxxxx.py works in console.