Why don't you set the value directly from the view functions ?
return render_to_response('index.html', {'val': dict[msg.status]})
On Thu, 2009-10-08 at 23:51 -0700, valler wrote:
> How can i use dictionary values in example below?
>
> def index(request):
> msg = Msg.objects.all()
> dict = {0:'good',1:'bad'}
> return render_to_response('index.html',{'msg':msg,'dict':dict})
>
>
> index.html
>
> {% for m in msg %}
> .......
> {{m.status}} -> displays 0 or 1, I want to use my dict here
> {{dict.m.status}} -> nothing, but
> {{dict.0}} -> works
> {{dict.1}} -> works
> {% endfor %}
>
> How can i use dictionary? Of course, i can write something like that:
>
> {% for m in msg %}
> .......
> {% for key,val in dict.items %}
> {% ifequal key m.status%} {{val}} {% endifequal %}
> {% endfor %}
> {% endfor %}
>
> But i find this solution ugly. Is there any other way?
> Thanks.
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---