I'm trying to learn Django and am finding it frustratingly difficult to do fairly basic things. I have the following form classes:
from django import forms
class InputForm(forms.Form):
field1 = forms.FloatField(label="First field: ")
field2 = forms.FloatField(label="Second field: ")
class OutputForm(forms.Form):
outfield = forms.FloatField(label="Result: ")
And the following template:
<form>
{{ input_form.as_ul }}
<input type="submit" class="btn" value="Submit" name="submit_button">
</form>
<form>
{{ output_form.as_ul }}
</form>
And finally, the following view:
from django.shortcuts import render
from .forms import InputForm, OutputForm
def index(request):
if request.GET.get('submit_button'):
# ?????
else:
input_form = InputForm()
output_form = OutputForm()
return render(request, 'index.html', {'input_form': input_form,
'output_form': output_form})
All I want to happen is that when I hit the submit button, the values in first field and second field get added and displayed in the result field. I know from debug outputs that the ????? commented block is run when I press the button, but I have so far not been able to figure out what to do to actually access or alter the data in my fields. I don't care about keeping a record of these transactions so it feels like storing these in a database is tremendous overkill. What is the correct way to approach this?