Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8984641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:09:23+00:00 2026-06-15T21:09:23+00:00

I have an array which prints the list of some elements. I want to

  • 0

I have an array which prints the list of some elements. I want to print those elements in a group of say ‘4’. That is if our array has 10 elements. Then in my template first <div> shows first 4 elements and next <div> shows next 4 elements. and so on.

I have tried to print like as we prints in PHP but it does not work here so please suggest me some way to do that.

There are 9 products in c.list and i want to show them as i have mentioned above:

{% if c.list|length >= 1 or c.list|length < 5 %}
        {% for p in c.list %}

        <div class="dis_box1">

        <div class="item_imagebox_01"><a href="/shop/product/{{p.title}}"><img style ="width:145px;height:190px;"alt="" src="{{ MEDIA_URL }}{{p.image}}"></a>
        <div class="img_line1"></div>
        </div>

        <div class="left"><span class="heart_text1"><a href="/shop/product/jhgjgj/">{{p.title}}</a></span></div>

            </div> 

        {% endfor %}
{% endif %}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:09:24+00:00Added an answer on June 15, 2026 at 9:09 pm

    This is the kind of work you should really be doing in your view.

    In your view:

    list_by_fours = []
    list_len = len(c.list)
    last_point = 0
    next_point = 4
    
    while last_point < list_len:
      if next_point > list_len:
        next_point = list_len
      list_by_fours.append(c.list[last_point:next_point])
      last_point += 4
      next_point += 4
    
    #Make sure you add list_by_fours to the template context
    

    Then in your template:

    {% for bucket in list_by_fours %}
            {% for p in bucket %}
                 ...
            {% endfor %}
    {% endif %}
    

    I’m sure there’s a way to do this with itertools or some other fancy trick, but this is clean and easy to understand for beginners.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 2D array. Lets suppose that it has some connected region which
I have an array which I want to use in a query: Array (
I have an array which contains 12 numbers and I want to save this
I have an array which has many values in it . I just wanted
I have a list of numpy arrays of different lengths, some of which repeat,
I have an array which describes a polyline (ordered list of connected straight segments)
I have written such the code below that ; I have an array list
I have a program that has an array of pointers such as: INTLIST* myArray[countOfRows];
I have a string which has been sent using udp. Now I want to
I have an array of floating-point numbers, which is unordered. I know that the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.