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 686877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:04:09+00:00 2026-05-14T02:04:09+00:00

in my Django 1.1.1 application I’ve got a function in the view that returns

  • 0

in my Django 1.1.1 application I’ve got a function in the view that returns to his template a range of numbers and a list of lists of items, for example:

...  
data=[[item1 , item2, item3], [item4, item5, item6], [item7, item8, item9]]  
return render_to_response('page.html', {'data':data, 'cycle':range(0,len(data)-1])

Inside the template I’ve got an external for loop, that contains also another for cycle to display in output the contains of the inner lists of data in this way

...  
{% for page in cycle %}   
...   
< table >   
{% for item in data.forloop.counter0 %}  
< tr >< td >{{item.a}} < /td > < td > {{item.b}} ... < /td > < /tr >  
...  
< /table >  
{% endfor %}  
{% if not forloop.last %}  
< div class="page_break_div" >  
{% endif %}  
{% endfor %}  
... 

But Django template engine doesn’t work with the forloop.counter0 value as index for the list (instead it does if I manually put a numeric value as index). Is there a way to let the list loop works with the external forloop.counter0 value?
Thanks in advance for the help 🙂

  • 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-05-14T02:04:09+00:00Added an answer on May 14, 2026 at 2:04 am

    You can’t use variables for attribute names, dictionary keys or list indices.

    Also range(0,len(data)-1] is not valid python. It should be range(len(data)).

    You probably don’t need cycle. Maybe what you want is this:

    {% for itemlist in data %}
        ...
        <table>
            {% for item in itemlist %}
            <tr>
              <td>{{ item.a }}</td>
              <td>{{ item.b }} ... </td>
            </tr>
            ...
            {% endfor %}
        </table>
        {% if not forloop.last %}
            <div class="page_break_div">
        {% endif %}
    {% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Django application that provides template tag profile . The tag accepts
in my Django application I've got a form with a ChoiceField that normally allows
I have a Django application that have a lot of images items that have
I've got a Django application that's running fine in debug mode. By running fine
I am developing a Django application, which is a large system that requires multiple
I'm trying to practise deploying a django application that is being developed. i've updated
I have a django application that creates xls and txt files. I'm trying to
I have a django application which uses a library.py file : library.py a=5 View
I have a Django application that I would like to deploy to the desktop.
I am writing a Django application that will track changes to the models, in

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.