3👍
✅
You should add this at the end of calculation() :
return HttpResponseNotAllowed(['POST'])
or redirect to the form page :
return redirect('your-form-view')
Then, if you call the page, you’ll either enter the if
and have your data managed, or raise your exception or have your redirection.
Without this, if your if
doesn’t validate, the default behaviour is returning None
, which for some reason seems to be occuring to you.
EDIT :
Also, your form is missing {% csrf_token %}
. But I don’t know why you’re not seeing a CSRF validation error. Maybe you’re developping without debug = True
? Anyway, a view should always return an http response, or redirect to another page, so even if none of this is your answer, you should manage the case where the method is GET.
Source:stackexchange.com