The element disappears when I add the tag {% include%} inside the for loop

Here is my template code for my queryset request:

{% block comments %}
{% load el_pagination_tags %}
    {% paginate 10 comment_list %}
        {% for i in comment_list %}
            <div class='comment_div'>
                <div class="left_comment_div">
                    <p>{{ i.comment_text }}</p>
                </div>
            </div>
            {% include 'comment/comments.html' with comment_list=i.replies.all %}
        </div>
        {% endfor %}
    {% show_more %}  
{% endblock %}

I am using django el pagination to implement ajax pagination. On the third line, you see that I initially upload 10 comments. With this package, an element appears {% show_more %} that you can add , which, when clicked, will load the rest of the comments.

However, this element {% show_more %}disappears for some reason when I add {% include 'comment/comments.html' with comment_list=i.replies.all %}. For context, this tag includeshows the responses for the current comment in a for loop.

Does anyone know why this tag affects an element {% show_more %}?

: show_more Github Source

el_pagination_tags.py

# show the template only if there is a next page
if page.has_next():
    print('Has next') #doesn't print
    request = context['request']
    page_number = page.next_page_number()
    # Generate the querystring.
    querystring_key = data['querystring_key']
    querystring = utils.get_querystring_for_page(
        request, page_number, querystring_key,
        default_number=data['default_number'])
    return {
        'label': label,
        'loading': loading,
        'class_name': class_name,
        'path': iri_to_uri(data['override_path'] or request.path),
        'querystring': querystring,
        'querystring_key': querystring_key,
        'request': request,
    }
# No next page, nothing to see.
print('No next') #prints for every comment (e.g. 20 times when 20 comments)
return {}

- , , , , , ? .

+6
3

, if include :

        {% if i.replies.all %}
            {% include 'comment/comments.html' with comment_list=i.replies.all %}
        {% else %}

include, 1 . , , .

+2

, / , show_more.

, , show_more templatetag ( python, ).

django-el-pagination/el_pagination/templatetags/el_pagination_tags.py # 330 (https://github.com/shtalinberg/django-el-pagination):

# This template tag could raise a PaginationError: you have to call
# *paginate* or *lazy_paginate* before including the showmore template.
data = utils.get_data_from_context(context)
page = data['page']
# show the template only if there is a next page
if page.has_next():
    request = context['request']
    page_number = page.next_page_number()
    # Generate the querystring.
    querystring_key = data['querystring_key']
    querystring = utils.get_querystring_for_page(
        request, page_number, querystring_key,
        default_number=data['default_number'])
    return {
        'label': label,
        'loading': loading,
        'class_name': class_name,
        'path': iri_to_uri(data['override_path'] or request.path),
        'querystring': querystring,
        'querystring_key': querystring_key,
        'request': request,
    }
# No next page, nothing to see.
return {}

show_more , :

  • page
  • querystring (. django-el-pagination/el_pagination/templates/el_pagination/show_more.html)
+2

. comment_list - .

{% include 'comment/comments.html' with replies=i.replies.all %}
+1

All Articles