I have realtime printed the output of my subprocess command onto an an html page using the below code in my views.py . However i want to print this output onto my html template (results.html). how do i do that ?
from django.shortcuts import redirect, render
from django.http import HttpResponse,HttpResponseRedirect,request
import subprocess
# Create your views here.
def home(request):
return render(request,"home.html")
def about(request):
return render (request,"About.html")
def contact(request):
return render (request,"Contact.html")
def process(request):
ip=request.POST.get('ip')
with subprocess.Popen(['ping', '-c5',ip], stdout=subprocess.PIPE, bufsize=1, universal_newlines=True) as p:
for line in p.stdout:
yield("<html><title>Fetcher Results</title><body><div style='background-color:black;padding:10px'><pre style='font-size:1.0rem;color:#9bee9b;text-align: center;'><center>"+line+"<center></div></html> ") # process line here
if p.returncode != 0:
raise subprocess.CalledProcessError(p.returncode, p.args)
def busy(request):
from django.http import StreamingHttpResponse
return StreamingHttpResponse(process(request))