Monday, February 29, 2016

Re: mathematical function and django connect



On Sun, Feb 28, 2016 at 2:06 PM, Xristos Xristoou <saxri89@gmail.com> wrote:
update my project now

my view.py code

def calc(request):
a = []
NList = []
y=0
member=0
member = request.POST.get ('member', False)
for i in range(int(member)):
input = request.POST.get ('input', False)
NList.append(int(input))
for k in NList:
if k is 1:
y = 1
elif (k > 1) and (k < 5):
y = (k - 1) + 2
a.append(y)
return render_to_response ('blog/calc.html', {'a' :a, 'member':member}, context_instance=RequestContext(request))


Have you verified that 'member' and 'input' are populated with values when the form is submitted? You should be able to put print() statements at various points in your code and watch the output on the dev server console. You should also check that the 'a' variable is populated just before it is placed into the context. 

Also, be careful using input as a variable name. That clashes with the input() function in Python 3. 

-James

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciXAzQNL4831UPxahzHQbn8nxsfB6ZWYkz9ofKRCPLtr-Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment