How to call a view function with argument from template and return a python object in Django?
<p>Here is the questions 
now I want call a view function from template/html with argument 
the function most like </p>

<pre><code>def function(PageToken,ID):
  '''Do Something Here'''
  comments = [[User1,Comment1],[User2,Comment2]]
  return comments
</code></pre>

<p>And how I call this function and Use like</p>

<pre><code>{%for comment in comments %}
  &lt;li&gt;                          
    {{comment.1}}
    {{comment.2}}
  &lt;/li&gt;
 {%endfor%}
</code></pre>

<p>And I dont want 
Reload the page 
how to do that</p>

<p>you can define your own custom template filter that takes arguments. </p>

<pre><code># in custom_tags.py  
from django import template

register = template.Library()

def build_comments(pagetoken, id):
    # build comments 
    return comments # it can also be queryset  
register.assignment_tag(build_comments)
</code></pre>

<p>in template: </p>

<pre><code>{% load custom_tags %}

{% build_comments pagetoken id as comments %}
{% for comment in comments %}
    &lt;li&gt;                          
       {{comment.1}}
       {{comment.2}}
    &lt;/li&gt;
{% endfor %}
</code></pre>

<p>full documentation ---> <a href="https://docs.djangoproject.com/en/1.10/howto/custom-template-tags/#custom-template-tags-and-filters" rel="nofollow">here</a> </p>

javascript python html ajax django