Django/Ajax update existing template page

19 views
Skip to first unread message

aysh...@gmail.com

unread,
Jun 22, 2016, 2:31:02 PM6/22/16
to Django users
Hello everyone,

I am trying to do the following:

Grab Year/Month values from a template page via dropdown select list and send them via ajax post (this part is working)

Process the submitted values and return new variables to the same template page, it works if I hard code the Month/Year but it won't display anything when I change values and re-submit them.

In the console I can print selected Month/Year and values for the 3 variables without any issues, but the template page is not displaying anything


Thanks!


here is my code: 

page.html

  {% for item1, item2, item3 in list_results %}
<td>{{ item1 }}</td>
<td>{{ item2 }}</td>
<td>{{ item3 }}</td>

</tr>
{% endfor %}
views.py
def data_web(request):

if request.method == 'POST':
year = request.POST.get('the_year')
month = request.POST.get('the_month')
year = int(year)
month = int(month)

var1
, var2, var3 = count_files(year, month)
list_results = zip(var1, var2, var3)
        print "Year", year, "month", month, list_results

return render(request, 'page.html', {'list_results': list_results})
else:
return render(request, 'page.html')


ludovic coues

unread,
Jun 22, 2016, 2:51:19 PM6/22/16
to django...@googlegroups.com
Have you tried {{item1|pprint}} ?
Or to check the raw page, not the one displayed by the brother ?
I got bitten more than once by brother not displaying variable whose
value looked like <Object date>
> --
> 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...@googlegroups.com.
> To post to this group, send email to django...@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/e4a5ea8f-3b44-44d8-8946-7e6d7f131463%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

Ahmed Shalaby

unread,
Jun 22, 2016, 3:00:42 PM6/22/16
to django...@googlegroups.com
Thanks for your reply,

It works if I hardcode the values, but if I set them to the ones passed from the selection list it won't work on the template page, but inside the console I see the values are being passed from template page to the views fine without problems, I can get the results for var1, var2,var3 fine as well, but all in the console. 

Thanks

You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/MV2Omxkp804/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages