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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:09:57+00:00 2026-05-30T17:09:57+00:00

I have a view like this: info_dict = [{u’Question 1′: [‘13365’, ‘13344’]}, {u’Question 2′:

  • 0

I have a view like this:

info_dict =  [{u'Question 1': ['13365', '13344']}, {u'Question 2': ['13365']}, {u'Question 3': []}]

for key in info_dict:
    for k, v in key.items():
        profile = User.objects.filter(id__in=v, is_active=True)
    for f in profile:
        wanted_fields = ['job', 'education', 'country', 'city','district','area']
        profile_dict = {}
        for w in wanted_fields:
            profile_dict[f._meta.get_field(w).verbose_name] = getattr(f, w).name

return render_to_response('survey.html',{
    'profile_dict':profile_dict,
},context_instance=RequestContext(request))

and in template:

<ul>
    {% for k, v in profile_dict.items %}
        <li>{{ k }} : {{ v }}</li>
    {% endfor %}
</ul>

I have only one dictionary in template. But 4 dictionary might be here (because info_dict)
What is wrong in view?

Thanks in advance

  • 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-30T17:09:58+00:00Added an answer on May 30, 2026 at 5:09 pm

    In your view, you’ve only created one variable (profile_dict) to hold the profile dicts.

    In each iteration of your for f in profile loop, you’re re-creating that variable, and overwriting its value with a new dictionary. So when you include profile_dict in the context passed to the template, it holds the last value assigned to profile_dict.

    If you want to pass four profile_dicts to the template, you could do this in your view:

    info_dict =  [{u'Question 1': ['13365', '13344']}, {u'Question 2': ['13365']}, {u'Question 3': []}]
    
    # Create a list to hold the profile dicts
    profile_dicts = []
    
    for key in info_dict:
        for k, v in key.items():
            profile = User.objects.filter(id__in=v, is_active=True)
        for f in profile:
            wanted_fields = ['job', 'education', 'country', 'city','district','area']
            profile_dict = {}
            for w in wanted_fields:
                profile_dict[f._meta.get_field(w).verbose_name] = getattr(f, w).name
    
            # Add each profile dict to the list
            profile_dicts.append(profile_dict)
    
    # Pass the list of profile dicts to the template
    return render_to_response('survey.html',{
        'profile_dicts':profile_dicts,
    },context_instance=RequestContext(request))
    

    And then in your template:

    {% for profile_dict in profile_dicts %}
    <ul>
        {% for k, v in profile_dict.items %}
            <li>{{ k }} : {{ v }}</li>
        {% endfor %}
    </ul>
    {% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a mvc2 application with a view like this <% using (Ajax.BeginForm(UserApprove, new
I have a View that renders something like this: Item 1 and Item 2
I have added a UILabel to my view programmatically like this: myLabel = [[UILabel
Let's say I have some classes like this: abstract class View(val writer: XMLStreamWriter) {
I'm having some difficulties with Ajax.BeginForm I have something like this in a view
i have view like 'home/details/5', it can be access by anonymous user. but there
I have a view and collection like this: window.DmnView = Backbone.View.extend({ template: _.template($(#tmpl_dmnListItem).html()), events:
I have a razor view that looks like this @using(Html.BeginForm(MVC.Account.Info())) { <p>blah blah blah</p>
I have a custom TabHost that adds tabs like this private void setTab(View view,
I have 2 methods like this in my user_helper.rb def full_name(user) if user.last_name? user.first_name

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.