|
List Info
Thread: Views, Templates, and Dictionaries
|
|
| Views, Templates, and Dictionaries |

|
2008-01-02 22:40:58 |
I have a simple view:
def index(request):
this_dict = { 'one':'1111','two':'2222', 'three':'3333'}
c = Context({"this_dict":this_dict})
return HttpResponse(t.render(c))
my template is like so:
{% for i in this_dict %}
key: {} <br>
value: {{this_dict.i}} <br>
{% endfor %}
When the view is rendered it only prints the dictionary keys
and not
the values:
key: one
value:
key:two
value:
key:three
value:
What am I doing wrong here? Any help would be greatly
appreciated.
Thanks.
- Brandon
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-users googlegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: Views, Templates, and Dictionaries |
  United States |
2008-01-02 22:46:47 |
This might help...
from: http://www.djangoproject.com/documentation/templates/#f
or
{% for key, value in this_dict.items %}
{}: {}
{% endfor %}
-Bill
On Jan 2, 2008, at 8:40 PM, brandonl wrote:
>
> I have a simple view:
>
> def index(request):
> this_dict = { 'one':'1111','two':'2222',
'three':'3333'}
> c = Context({"this_dict":this_dict})
> return HttpResponse(t.render(c))
>
> my template is like so:
>
> {% for i in this_dict %}
> key: {} <br>
> value: {{this_dict.i}} <br>
> {% endfor %}
>
> When the view is rendered it only prints the dictionary
keys and not
> the values:
>
> key: one
> value:
> key:two
> value:
> key:three
> value:
>
> What am I doing wrong here? Any help would be greatly
appreciated.
> Thanks.
>
> - Brandon
>
> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to
the Google
> Groups "Django users" group.
> To post to this group, send email to django-users googlegroups.com
> To unsubscribe from this group, send email to
django-users-unsubscribe googlegroups.com
> For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
> -~----------~----~----~----~------~----~------~--~---
>
|
|
| Re: Views, Templates, and Dictionaries |
  United States |
2008-01-02 22:47:12 |
>From the template docs:
http://www.djangoproject.com/documentation/templates/
{% for key, value in data.items %}
{}: {}
{% endfor %}
Note that this is for the svn version of django.
brandonl wrote:
> I have a simple view:
>
> def index(request):
> this_dict = { 'one':'1111','two':'2222',
'three':'3333'}
> c = Context({"this_dict":this_dict})
> return HttpResponse(t.render(c))
>
> my template is like so:
>
> {% for i in this_dict %}
> key: {} <br>
> value: {{this_dict.i}} <br>
> {% endfor %}
>
> When the view is rendered it only prints the dictionary
keys and not
> the values:
>
> key: one
> value:
> key:two
> value:
> key:three
> value:
>
> What am I doing wrong here? Any help would be greatly
appreciated.
> Thanks.
>
> - Brandon
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-users googlegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| Re: Views, Templates, and Dictionaries |

|
2008-01-02 22:53:38 |
Thanks.
On Jan 2, 8:47 pm, Jeff Anderson <jeffe... programmerq.net> wrote:
> From the template docs:http://www.djangoproject.com/documentation/templates/
>
> {% for key, value in data.items %}
> {}: {}
> {% endfor %}
>
> Note that this is for the svn version of django.
>
> brandonl wrote:
> > I have a simple view:
>
> > def index(request):
> > this_dict = { 'one':'1111','two':'2222',
'three':'3333'}
> > c = Context({"this_dict":this_dict})
> > return HttpResponse(t.render(c))
>
> > my template is like so:
>
> > {% for i in this_dict %}
> > key: {} <br>
> > value: {{this_dict.i}} <br>
> > {% endfor %}
>
> > When the view is rendered it only prints the
dictionary keys and not
> > the values:
>
> > key: one
> > value:
> > key:two
> > value:
> > key:three
> > value:
>
> > What am I doing wrong here? Any help would be
greatly appreciated.
> > Thanks.
>
> > - Brandon
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-users googlegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
[1-4]
|
|
|
about | contact Other archives ( Real Estate discussion Medical topics )
|