7
我有這樣一個觀點:字典在Django模板
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))
和模板:
<ul>
{% for k, v in profile_dict.items %}
<li>{{ k }} : {{ v }}</li>
{% endfor %}
</ul>
我在模板中只有一個字典。但4字典可能在這裏(因爲info_dict) 視圖有什麼問題?
在此先感謝
你救了我的命。謝謝 – TheNone 2012-03-02 10:39:38
@TheNone:crikey,你的老闆*真的很嚴格。你非常歡迎。 – 2012-03-02 10:48:34