title: Using data returned from forms in Django
body: <p>Sorry for being a little new. My goal is to use the data collected from a user form to output a graph. The user inputs an initial 'price' then submits this number, it then goes into my formulas written in python and then django should display a chart in the same HTML file. I'm currently stuck on how to use data from 'POST'. </p>
  
  <p>For example, if I'd like to take the cleaned_data from 'strike1' and multiply it by 4, then display it on the webpage, how would I go about doing that?   </p>
  
  <p>views.py</p>
  
  <pre><code>from django.shortcuts import render
  from .forms import DataForm
  
  # Create your views here.
  
  def data(request):
  
      if request.method == 'POST':
          form = DataForm(request.POST)
          if form.is_valid():
  
              strike1 = form.cleaned_data['strike1']
              strike2 = form.cleaned_data['strike2']
              strike3 = form.cleaned_data['strike3']
              strike4 = form.cleaned_data['strike4']
              strategy = form.cleaned_data['strategy']
              price = range(0,50)
              premium1 = form.cleaned_data['premium1']
              premium2 = form.cleaned_data['premium2']
              premium3 = form.cleaned_data['premium3']
              premium4 = form.cleaned_data['premium4']
              contracts = form.cleaned_data['contracts']
  
  
  
      form = DataForm()
      return render(request, 'form.html', {'form': form})
  </code></pre>
  
  <p>forms.py</p>
  
  <pre><code>from django import forms
  
  
  class DataForm(forms.Form):
  
      strategy = forms.ChoiceField(
              choices=[('Long Call', 'Long Call'), ('Long Put', 'Long Put'), ('Short Call', 'Short Call',),
                       ('Short Put', 'Short Put'), ('Bull Call Spread', 'Bull Call Spread'),
                       ('Bear Put Spread', 'Bear Put Spread'), ('Straddle', 'Straddle'),
                       ('Butterfly Spread', 'Butterfly Spread'),
                       ('Box Spread', 'Box Spread'), ('Iron Condor', 'Iron Condor')])
      strike1 = forms.FloatField()
      strike2 = forms.FloatField()
      strike3 = forms.FloatField()
      strike4 = forms.FloatField()
  
      premium1 = forms.FloatField()
      premium2 = forms.FloatField()
      premium3 = forms.FloatField()
      premium4 = forms.FloatField()
  
      contracts = forms.IntegerField()
  </code></pre>
  
  <p>form.html</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;Website&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form method="'post"&gt;
  
          {% csrf_token %}
  
          {{ form }}
  
          &lt;button type="Submit"&gt;Generate&lt;/button&gt;
  
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>