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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:06:15+00:00 2026-05-23T18:06:15+00:00

I am having trouble in understanding how to iterate over QuerySet , Tuple and

  • 0

I am having trouble in understanding how to iterate over QuerySet , Tuple and Dictionarty in django.

I am confused which djnago functions returns what like objects.all or objects.get

Suppose i have

a = model.objects.all()
b = model.object.get(pk=1)
c = Blog.objects.values('name', 'entry__headline')
d = Entry.objects.values_list('id', 'headline')
e = Person.objects.raw('SELECT * FROM myapp_person')

What is the retured in each scenario and the biggest problem is how can i iterate over.
All these confuse me very much . I studies the docs but they tell one thing and don’t tell how to use in template. I know its related to python but then python don’t have template to deal with

  • 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-23T18:06:16+00:00Added an answer on May 23, 2026 at 6:06 pm

    Are you referring to these docs? https://docs.djangoproject.com/en/dev/ref/templates/builtins/#for

    I think that’s what you were looking for.

    Basically you iterate over them like:

    {% for item in a %}
    {{item.field}}
    {{item.field2}}
    {% endfor %}
    
    {{b.field}}
    
    {% for item in c %}
    {{item.name}}
    {{item.entry__headline}}
    {% endfor %}
    
    {% for item in d %}
    {{item}}
    {% endfor %}
    
    # Also you can do this if you want to access just a particular index:
    {{d.0}}
    {{d.1}}
    
    {% for item in e %}
    {{item.field}}
    {{item.field2}}
    {% endfor %}
    

    As for your data types:
    a would be a QuerySet or list of model objects
    b would be a model object
    c would be a ValuesQuerySet or a list of dictionaries
    d would also be a ValuesQuerySet but it’s actually a list of tuples
    e would be a RawQuerySet, which acts like a normal QuerySet

    Sources:
    https://docs.djangoproject.com/en/dev/topics/db/sql/#django.db.models.Manager.raw
    https://docs.djangoproject.com/en/dev/ref/models/querysets/#values
    https://docs.djangoproject.com/en/dev/ref/models/querysets/#values-list

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

Sidebar

Related Questions

I'm having trouble understanding the for/in statement in JavaScript. The book which I'm using
I'm having trouble understanding why a WSDL would be so beneficial, when the truth
I am having trouble understanding how the System Registry can help me convert a
I'm having trouble understanding when to use properties in Objective C 2.0. It seems
I'm having trouble understanding why I would use a context.xml file to declare a
I am still having trouble understanding what interfaces are good for. I read a
I'm having trouble understanding this question, and the explanation of the answer for an
I am having trouble understanding why NSLog reports dog when the code is run.
I'm having trouble understanding the API to set up a l2cap (or RFCOMM) client/server
I'm having trouble understanding the behavior of the estimated query plans for my statement

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.