Rajeesh,
Following your advice, Im think I've about solved the problem.
I've got one last exception, I hope.
Here is the new iteration of views.py, all other files remain the same.
In short the page renders to the screen, the problem arises when values are submitted
to the view.
I get an exception "can't multiply sequence by non-int of type 'tuple". I've created a new
function that describes the multiplication operation, that is used within the render function, this
is where the error occcrs. I'm not referencing the variables properly, I guess.
def calculation(request):
"""function that computes submission"""
if request.method == 'POST':
form = FinanceTable(request.POST)
if form.is_valid():
cd =form.cleaned_data
capital = cd['capital'],
tax_rate = cd['tax_rate'],
useage = projfin(request, capital, tax_rate)
response_dict = {'capital' : capital, 'tax_rate' : tax_rate, 'useage' : useage}
return render_to_response('textplusnumbers.html' , response_dict)
else:
form = FinanceTable(
initial={'capital' : 1000, 'tax_rate' : .07}
)
return render_to_response('textplusnumbers.html' , {'form' : form})
def projfin(request, capital, tax_rate):
useage = capital * tax_rate
return useage
On Mon, Mar 19, 2012 at 1:10 PM, Rajeesh Nair <rajeeshrnair@gmail.com> wrote:
Your FormClass expects all 3 fields to be optional (required=False). But your code in view always expects them to have integer values. And you end up multiplying values from two blank fields! Either you provide some default value to the fields or rewrite view to use form.cleaned_data.get with a default value as 2nd argument to it.
On Monday, March 19, 2012 9:11:27 PM UTC+5:30, bolivar4 wrote:--"unsupported operand type(s) for *: 'NoneType' and 'NoneType'"class FinanceTable(forms.Form):capital = forms.IntegerField(required=False)tax_rate = forms.DecimalField(required=False)useage = forms.IntegerField(required=False)You received this message because you are subscribed to the Google Groups "Django users" group.To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/CFfpFTLoPSMJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment