title: How Can I Run a Function Inside of Views.py and Print Result? -- Django
body: <p>The problem is that I am trying to call a function from my views.py and print the result in my template through a context variable. The function prints in the terminal and does not work in the template. I posted a question a few days ago regarding doing this with subprocess, but I still could not figure it out.</p>
  
  <p>How can I print "This is a test function for AAPL" in my template instead of in the terminal?</p>
  
  <p><strong>Views.py</strong></p>
  
  <pre><code>from django.shortcuts import render  
  from backtests.scripts import Backtests
  
  def index(request):
  
      if 'symbol' in request.GET:
          symbol = request.GET.get('symbol','Invalid Symbol')
          request.session['symbol'] = symbol
      else:
          symbol = request.session['symbol']
  
  
      earnings_object = Backtests("AAPL")
      test = earnings_object.print_discrep()
  
  
      return render(request, 'backtests/earnings.html', {'symbol':symbol, 'test':test})
  </code></pre>
  
  <p><strong>scripts.py</strong></p>
  
  <pre><code>class Backtests:
  
      def __init__(self, symbol):
          self.symbol = symbol
  
      def print_discrep(self):
          print('This is a test function for the graph ' + self.symbol)
  </code></pre>
  
  <blockquote>
    <p>It is returning None in my template.</p>
  </blockquote>