I'm new in Django ,and I'm trying to develop a simple Django application which takes two numbers from the user with a form and do some operation with those numbers and print the result with a Http Response. My code is the following:
forms.py
class SimpleForm(forms.ModelForm):
a = forms.IntegerField(label='first' )
b = forms.IntegerField(label='second' )
def result(self):
return doSomething(self.a, self.b)
views.py
class MainPage(FormView):
template_name = 'simple.html'
success_url = '/result/'
form_class = SimpleForm
def form_valid(self, form):
return HttpResponse(form.result())
However, when I run this code on my localhost, it gives the error like
SimpleForm object has no attribute 'a'
So, what can be the problem? How can I get the user input in order to use it in my "result" function?
Thanks in advance...