Python论坛  - 讨论区

标题:[python-chinese] 怎么在django的模板里面得到传入字典的key?

2007年12月06日 星期四 08:57

温铭 wenming在kingsoft.net
星期四 十二月 6 08:57:10 HKT 2007

对于list可以用{% for a in list%}  来处理。那传入一个dict怎么得到key和对应的值呢?谢谢

-- 
wayne
-------------- 下一部分 --------------
一个HTML附件被移除...
URL: http://python.cn/pipermail/python-chinese/attachments/20071206/d54927ec/attachment-0001.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年12月06日 星期四 10:59

wang bin wangbin1979在gmail.com
星期四 十二月 6 10:59:40 HKT 2007

在 07-12-6,温铭<wenming在kingsoft.net> 写道:
> 对于list可以用{% for a in list%}  来处理。那传入一个dict怎么得到key和对应的值呢?谢谢
>
> --
> wayne
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to
> python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to
> python-chinese-request在lists.python.cn
> Detail Info:
> http://python.cn/mailman/listinfo/python-chinese
>

{% for key, value in dict.items %}{{ key }}{{ value }}{% endfor %}
-- 
想飞之心,永远不死!
Registered Linux User 404987 [http://counter.li.org]

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年12月06日 星期四 11:46

@@ askfor在gmail.com
星期四 十二月 6 11:46:39 HKT 2007

x.y¾Í¿ÉÒÔÁË


Dots have a special meaning in template rendering. A dot in a variable name
signifies *lookup*. Specifically, when the template system encounters a dot
in a variable name, it tries the following lookups, in this order:

   - Dictionary lookup. Example: foo["bar"]
   - Attribute lookup. Example: foo.bar
   - Method call. Example: foo.bar()
   - List-index lookup. Example: foo[bar]




On 12/6/07, wang bin <wangbin1979在gmail.com> wrote:
>
> ÔÚ 07-12-6£¬ÎÂÃú<wenming在kingsoft.net> дµÀ£º
> > ¶ÔÓÚlist¿ÉÒÔÓÃ{% for a in list%}  À´´¦Àí¡£ÄÇ´«ÈëÒ»¸ödictÔõôµÃµ½keyºÍ¶ÔÓ¦µÄֵĨ£¿Ð»Ð»
> >
> > --
> > wayne
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to
> > python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to
> > python-chinese-request在lists.python.cn
> > Detail Info:
> > http://python.cn/mailman/listinfo/python-chinese
> >
>
> {% for key, value in dict.items %}{{ key }}{{ value }}{% endfor %}
> --
> Ïë·ÉÖ®ÐÄ£¬ÓÀÔ¶²»ËÀ£¡
> Registered Linux User 404987 [http://counter.li.org]
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20071206/31a25b58/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年12月06日 星期四 19:35

Youhong Han python.han在gmail.com
星期四 十二月 6 19:35:48 HKT 2007

{% for entry in lst %}

{% endfor %}

On Dec 6, 2007 11:46 AM, @@ <askfor在gmail.com> wrote:

> x.y¾Í¿ÉÒÔÁË
>
>
> Dots have a special meaning in template rendering. A dot in a variable
> name signifies *lookup*. Specifically, when the template system encounters
> a dot in a variable name, it tries the following lookups, in this order:
>
>    - Dictionary lookup. Example: foo["bar"]
>    - Attribute lookup. Example: foo.bar
>    - Method call. Example: foo.bar()
>    - List-index lookup. Example: foo[bar]
>
>
>
>
> On 12/6/07, wang bin <wangbin1979在gmail.com> wrote:
> >
> > ÔÚ 07-12-6£¬ÎÂÃú<wenming在kingsoft.net> дµÀ£º
> > > ¶ÔÓÚlist¿ÉÒÔÓÃ{% for a in list%}  À´´¦Àí¡£ÄÇ´«ÈëÒ»¸ödictÔõôµÃµ½keyºÍ¶ÔÓ¦µÄֵĨ£¿Ð»Ð»
> > >
> > > --
> > > wayne
> > >
> > > _______________________________________________
> > > python-chinese
> > > Post: send python-chinese在lists.python.cn
> > > Subscribe: send subscribe to
> > > python-chinese-request在lists.python.cn
> > > Unsubscribe: send unsubscribe to
> > > python-chinese-request在lists.python.cn
> > > Detail Info:
> > > http://python.cn/mailman/listinfo/python-chinese
> > >
> >
> > {% for key, value in dict.items %}{{ key }}{{ value }}{% endfor %}
> > --
> > Ïë·ÉÖ®ÐÄ£¬ÓÀÔ¶²»ËÀ£¡
> > Registered Linux User 404987 [http://counter.li.org]
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to
> > python-chinese-request在lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20071206/6bd62e8f/attachment.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号