解码Django-temp中元组的值

2024-03-28 12:00:01 发布

您现在位置:Python中文网/ 问答频道 /正文

  if(len(f1) > 0):  
    for qs in profile_map:
        p = Profile.objects.get(pk=qs.emp.id)
        t_name = p.first_name + p.last_name
        t_arr.append((q.profile.id,emp_name))
    response_dictionary.update({'tarr':t_arr})
  render_to_response('project/profile_table.html',context_instance=RequestContext(request,{'response_dictionary': response_dictionary}))

在Django模板中,如何对元组2的所有1.values进行去编码。配置文件.id在

^{pr2}$

Tags: nameinidmapfordictionarylenif
2条回答

如果使用的是django 0.96,则for循环中不能有多个值。所以这行不通:

{% for first_name, last_name in response_dictionary.tarr %}

而是使用

^{pr2}$

在您的例子中,生成器将把元组赋给ele,这样您就可以用{{ ele.0 }} {{ ele.1 }}访问第一个姓。在

但将元组解压为两个变量也是合法的:

{% for first_name, last_name in response_dictionary.tarr %}

相关问题 更多 >