The simple idea of the app I am developing is user give the Linux commands and the result of Linux command will be shown in the webbrowser. Here's my views.py:
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.template import RequestContext
import subprocess
globalcmd = 0
globalresult = 0
def ls(request):
if request.method == 'POST':
globalcmd = request.POST.get('command', False)
globalresult = subprocess.call(['globalcmd'], shell=True)
return HttpResponseRedirect('/thanks/')
else:
pass
return render_to_response('form.html', {'cmd':'cmd'}, context_instance=RequestContext(request))
def show_template(request):
return render_to_response('thanks.html', {'globalok':globalresult}, context_instance=RequestContext(request))
I get input from form.html which is processed by view 'ls'. As a user I am just testing with ls command. Whenever I press ls command it is processed by suprocess.call and stored in globalresult which is later called in thanks.html. My output is 0. What am I doing wrong? Here's thanks.html:
<h1>
{{ globalresult }}
</h1>