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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:28:43+00:00 2026-06-12T14:28:43+00:00

Possible Duplicate: how to create counter loop in django template? I want to print

  • 0

Possible Duplicate:
how to create counter loop in django template?

I want to print some data based on some condition,

I want to use it like we used in other languages:

for(i=1;i<=count;i++)
print i

To do this in django I wrote

{% for i in count %}
<p>{{ i }}</p>
{% endfor %}

but it gives me an error ‘int’ object is not iterable.Count is coming from views.py and if I prints the count alone than it shows the output.

I wanted to print some value until count not becomes zero,So how i can do this in django.

And one more thing can we use while loop in django because i also try to use it for this task but it gives me the error of invalid block tag: ‘while’

So please let me know how can I do this task ?

Thanks

Edit
in my view.py I have used like this

count=Product_attributes.objects.count()

and then pass this count to my template

  • 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-12T14:28:45+00:00Added an answer on June 12, 2026 at 2:28 pm

    Django templates are not programming language. Write all you logic in the view or models, and pass data into the template:

    def view(request):
        values = []
        for i in range(10):
             values.append(i) # your custom logic here
        return render_to_response("/path/to/template", {'values': values})
    

    in template:

    {% for value in values %}
        <p>{{ value }}</p>
    {% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Create an Iframe from a Drupal Website I'd like to use an
Possible Duplicate: Create event handler for OnScroll for web browser control I would like
Possible Duplicate: create multiple variables based on an int count Objective C Equivalent of
Possible Duplicate: PHP create a file without fopen I want to create a file
Possible Duplicate: How to create a static (non-refreshing) menu bar like Facebook? How Facebook
Possible Duplicate: Create categorical variable in R based on range Given a range and
Possible Duplicate: How can I create a UIColor from a hex string? I want
Possible Duplicate: Create a date with T-SQL I've a data table that stores each
Possible Duplicate: create multiple variables based on an int count Objective C Equivalent of
Possible Duplicate: Jquery:: Ajax powered progress bar? I need to create some kind of

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.