title: How do I display the console output to HTML in Django?
body: <p>So I'm using Django framework to display the console output to the HTML. To execute the command, I'm using the <code>check_output</code> of <code>subprocess</code> module in Python. Which receives the input from the HTML input form. The problem is that I only see "<code>None</code>" on the HTML page, which is the default value of <code>output</code> in <code>views</code> file.
  Below is the code of the views file and HTML file. I'm a novice in this so I'd appreciate your assistance. </p>
  
  <p><strong>Views.py</strong></p>
  
  <pre><code>from django.shortcuts import render
  from django.shortcuts import redirect
  from .forms import command_form
  import subprocess as sp
  
  
  # Create your views here.
  
  def welcome_page(request):
      output=""
      if request.method == "POST":
          myform = command_form(request.POST)
          if (myform.is_valid()):
              execute_command = myform.cleaned_data['cmd_string']
              output = sp.check_output(execute_command, shell=True)
          else:
              myform = command_form()
          return render(request, 'ovs/welcome.html', {'output': output})
      else:
          return render(request, 'ovs/welcome.html', {})
  </code></pre>
  
  <p><strong>welcome.html</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;welcome to ovs GUI&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h3&gt;Choose the option:&lt;/h3&gt;
      &lt;form method="POST"&gt;{% csrf_token %}
          Enter the command: &lt;input type="text" name="cmd_string" id="cmd_string"/&gt;
          &lt;input type="submit" value="Run"/&gt;
      &lt;/form&gt;
      &lt;h3&gt;{{ output }}&lt;/h3&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>forms</strong></p>
  
  <pre><code>from django import forms
  
  
  class command_form(forms.Form):
      command = forms.CharField(max_length=200)
  </code></pre>