Return submitted form results back to the same html page


I have a form which submits three values through a function and I’m trying to get those results printed on the same html page where the form is. I can print the results in the terminal but not on the page.

Forms, Views, and HTML below. Thanks!


from django import forms

class CalculatorForm(forms.Form):
    value1 = forms.FloatField(required=False)
    value2 = forms.FloatField(required=False)
    value3 = forms.IntegerField(required=False)


class CalculatorView(TemplateView):
    template= 'calculator/calculator.html'

    def get(self, request):
        form_c = CalculatorForm(prefix='form_c')
        return render(request, self.template, {
            'form_c': form_c,

    def post(self, request):
        form_c = CalculatorForm(request.POST, prefix='form_c')
            if form_c.is_valid():
                post = form_c.cleaned_data
                value1 = post.get('value1')
                value2 = post.get('value2')
                value3 = post.get('value3')
                df1 = my_function(value1, value2, value3) # I want to print the results of this function on the page


        args = {
            'form_c': form_c,
        return render(request, self.template, args)


{% extends 'base.html' %}
<h1>Home Page</h1>

{% block head %}
{% endblock %}
{% block body %}
<div class="container">
      <form method="post">
          {% csrf_token %}
          {{ form_c.as_p }}
          <button type="submit">Submit</button>
<div class="container">
    # my_function results here <---
    {% endblock %}

You need to include the calculated value in your context, then include a variable reference in your template to render that value.