Python论坛  - 讨论区

标题:[python-chinese] [Django]到底用RequestContext去处理变量真的比template tag方便很多吗??

2007年09月13日 星期四 20:53

beck917 beck917在gmail.com
星期四 九月 13 20:53:50 HKT 2007

Using RequestContext and a context processor *automatically* adds these
variables in every template, which avoids the repetitiveness of having to
call a template tag in each template just to add some variables.

ÎҾͲ»Ã÷°×ÁËtemplate tagÔõôÂé·³ÁË,²»¾ÍÊÇдһ´Î,È»ºóÿ¸öÄ£°å{% variables %}ÕâÑùµ÷Óò»¾ÍÐÐÁË

µ½µ×RequestContext and a context processorÊÇÔõôһÖÖģʽ,¼´±ã¶¨ÒåÁËÒ»¸öеÄcontext
processor,µ½µ×ÔÚÄ£°åÖÐÔõôÓÃÄØ,ÒòΪһֱûÓÐÕÒµ½Ò»¸öÍê³ÉµÄÕâ¸ö¶«Î÷ÔËÓõÄÀý×Ó.ËùÒÔһͷÎíË®

Ï벻ͨ...Ôõô¾Í±Ètemplate tag¼òµ¥ÁË.
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070913/6561d10f/attachment.html 

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

2007年09月13日 星期四 20:57

beck917 beck917在gmail.com
星期四 九月 13 20:57:48 HKT 2007

http://www.b-list.org/weblog/2006/jun/14/django-tips-template-context-processors/

ÎÒÊÇ¿´µÄÕâƪ½Ì³Ì,ËûÓÃÁËÒ»¸ö MEDIA_URL<http://www.djangoproject.com/documentation/settings/#media-url>µÄÀý×Ó,ÎÒ²»Ã÷°×,ÄѵÀ
MEDIA_URL <http://www.djangoproject.com/documentation/settings/#media-url>
ÔÚDjangoÖв»ÊÇ×Ô¶¯Ìí¼Óµ½css,imageÕâЩÁ´½ÓÖеÄÂð?ÒòΪËûûÓоٳö¾ßÌåÄ£°åÖÐÓ¦ÓõĴúÂë..ËùÒÔºÜÄÑÀí½â

ÔÚ07-9-13£¬beck917 <beck917在gmail.com> дµÀ£º
>
> Using RequestContext and a context processor *automatically* adds these
> variables in every template, which avoids the repetitiveness of having to
> call a template tag in each template just to add some variables.
>
> ÎҾͲ»Ã÷°×ÁËtemplate tagÔõôÂé·³ÁË,²»¾ÍÊÇдһ´Î,È»ºóÿ¸öÄ£°å{% variables %}ÕâÑùµ÷Óò»¾ÍÐÐÁË
>
> µ½µ×RequestContext and a context processorÊÇÔõôһÖÖģʽ,¼´±ã¶¨ÒåÁËÒ»¸öеÄcontext
> processor,µ½µ×ÔÚÄ£°åÖÐÔõôÓÃÄØ,ÒòΪһֱûÓÐÕÒµ½Ò»¸öÍê³ÉµÄÕâ¸ö¶«Î÷ÔËÓõÄÀý×Ó.ËùÒÔһͷÎíË®
>
> Ï벻ͨ...Ôõô¾Í±Ètemplate tag¼òµ¥ÁË.
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070913/91007154/attachment.htm 

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

2007年09月13日 星期四 21:15

cun heise cunheise在hotmail.com
星期四 九月 13 21:15:07 HKT 2007

不知道你说的什么意思。举个具体的例子吧
你认为什么地方改用template tag 而不是应该用requestcontext


>From: beck917 <beck917在gmail.com>
>Reply-To: python-chinese在lists.python.cn
>To: python-chinese在lists.python.cn
>Subject: [python-chinese] [Django]到底用RequestContext去处理变量真的比
template tag方便很多吗??
>Date: Thu, 13 Sep 2007 20:53:50 +0800
>
>Using RequestContext and a context processor *automatically* adds these
>variables in every template, which avoids the repetitiveness of having to
>call a template tag in each template just to add some variables.
>
>我就不明白了template tag怎么麻烦了,不就是写一次,然后每个模板{% variables %}
这样调用不就行了
>
>到底RequestContext and a context processor是怎么一种模式,即便定义了一个新的
context
>processor,到底在模板中怎么用呢,因为一直没有找到一个完成的这个东西运用的例子
.所以一头雾水
>
>想不通...怎么就比template tag简单了.


>_______________________________________________
>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

_________________________________________________________________
与联机的朋友进行交流,请使用 Live Messenger; 
http://get.live.com/messenger/overview 


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

2007年09月13日 星期四 21:28

beck917 beck917在gmail.com
星期四 九月 13 21:28:19 HKT 2007

˵ʵ»°ÎÒû¾õµÃrequestcontext±Ètemplate tag·½±ãÔÚÄÄ..ÓÃrequestcontextµÄµØ·½¶¼¿ÉÒÔtemplate tagʵÏÖ.

ÎÒÏërequestcontextÖ÷ÒªÊÇÓÃÓÚһЩÔÚsettingÖж¨ÒåµÄ±äÁ¿(ÕâЩÐèÒªÔÚÄ£°åÖÐʹÓõıäÁ¿)
¶øtemplate tagÔòʵÏÖһЩ¸ü¸´ÔӵIJÙ×÷,±ÈÈç¶ÁÈ¡Êý¾Ý¿âÖеÄÊý¾ÝÏÔʾÔÚÄ£°åÖÐ

ÔÚ07-9-13£¬cun heise <cunheise在hotmail.com> дµÀ£º
>
> ²»ÖªµÀÄã˵µÄʲôÒâ˼¡£¾Ù¸ö¾ßÌåµÄÀý×Ó°É
> ÄãÈÏΪʲôµØ·½¸ÄÓÃtemplate tag ¶ø²»ÊÇÓ¦¸ÃÓÃrequestcontext
>
>
> >From: beck917 <beck917在gmail.com>
> >Reply-To: python-chinese在lists.python.cn
> >To: python-chinese在lists.python.cn
> >Subject: [python-chinese] [Django]µ½µ×ÓÃRequestContextÈ¥´¦Àí±äÁ¿ÕæµÄ±È
> template tag·½±ãºÜ¶àÂð??
> >Date: Thu, 13 Sep 2007 20:53:50 +0800
> >
> >Using RequestContext and a context processor *automatically* adds these
> >variables in every template, which avoids the repetitiveness of having to
> >call a template tag in each template just to add some variables.
> >
> >ÎҾͲ»Ã÷°×ÁËtemplate tagÔõôÂé·³ÁË,²»¾ÍÊÇдһ´Î,È»ºóÿ¸öÄ£°å{% variables %}
> ÕâÑùµ÷Óò»¾ÍÐÐÁË
> >
> >µ½µ×RequestContext and a context processorÊÇÔõôһÖÖģʽ,¼´±ã¶¨ÒåÁËÒ»¸öеÄ
> context
> >processor,µ½µ×ÔÚÄ£°åÖÐÔõôÓÃÄØ,ÒòΪһֱûÓÐÕÒµ½Ò»¸öÍê³ÉµÄÕâ¸ö¶«Î÷ÔËÓõÄÀý×Ó
> .ËùÒÔһͷÎíË®
> >
> >Ï벻ͨ...Ôõô¾Í±Ètemplate tag¼òµ¥ÁË.
>
>
> >_______________________________________________
> >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
>
> _________________________________________________________________
> ÓëÁª»úµÄÅóÓѽøÐн»Á÷£¬ÇëʹÓà Live Messenger;
> http://get.live.com/messenger/overview
>
> _______________________________________________
> 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/20070913/c68b25c3/attachment.html 

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

2007年09月13日 星期四 21:34

limodou limodou在gmail.com
星期四 九月 13 21:34:22 HKT 2007

On 9/13/07, beck917 <beck917在gmail.com> wrote:
> 说实话我没觉得requestcontext比template
> tag方便在哪..用requestcontext的地方都可以template tag实现.
>
> 我想requestcontext主要是用于一些在setting中定义的变量(这些需要在模板中使用的变量)
> 而template tag则实现一些更复杂的操作,比如读取数据库中的数据显示在模板中
>
这里的简单的指开发的简单吧,我是这么理解。写一个custom tag要比写一个TEMPLATECONTEXTPROCESSORS要难得多。

-- 
I like python!
UliPad <>: http://code.google.com/p/ulipad/
My Blog: http://www.donews.net/limodou

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

2007年09月13日 星期四 22:20

beck917 beck917在gmail.com
星期四 九月 13 22:20:00 HKT 2007

Using RequestContext and a context processor *automatically* adds these
variables in every template, which avoids the repetitiveness of having to
call a template tag in each template just to add some variables.
ÎҸоõÕâ¾ä»°µÄÒâ˼ÏñÊÇ˵ִÐÐЧÂʸß,ºóÒ»¾ä˵±ÜÃâÔÚÿ¸öÄ£°åÖÐcall a template tag,Ö»ÊÇÔö¼ÓÁËһЩ±äÁ¿

ÔÚ07-9-13£¬limodou <limodou在gmail.com> дµÀ£º
>
> On 9/13/07, beck917 <beck917在gmail.com> wrote:
> > ˵ʵ»°ÎÒû¾õµÃrequestcontext±Ètemplate
> > tag·½±ãÔÚÄÄ..ÓÃrequestcontextµÄµØ·½¶¼¿ÉÒÔtemplate tagʵÏÖ.
> >
> > ÎÒÏërequestcontextÖ÷ÒªÊÇÓÃÓÚһЩÔÚsettingÖж¨ÒåµÄ±äÁ¿(ÕâЩÐèÒªÔÚÄ£°åÖÐʹÓõıäÁ¿)
> > ¶øtemplate tagÔòʵÏÖһЩ¸ü¸´ÔӵIJÙ×÷,±ÈÈç¶ÁÈ¡Êý¾Ý¿âÖеÄÊý¾ÝÏÔʾÔÚÄ£°åÖÐ
> >
> ÕâÀïµÄ¼òµ¥µÄÖ¸¿ª·¢µÄ¼òµ¥°É£¬ÎÒÊÇÕâôÀí½â¡£Ð´Ò»¸öcustom tagÒª±Èдһ¸öTEMPLATECONTEXTPROCESSORSÒªÄѵöࡣ
>
> --
> I like python!
> UliPad <>: http://code.google.com/p/ulipad/
> My Blog: http://www.donews.net/limodou
> _______________________________________________
> 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/20070913/cd92fe60/attachment.htm 

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

2007年09月14日 星期五 10:17

beck917 beck917在gmail.com
星期五 九月 14 10:17:11 HKT 2007

ÏþµÃÁË.½ñÌìʵ¼ùÁËÏÂtemplate tag,
Ô­À´ÔÚÄ£°åÖл¹ÐèÒª{% load template_tag_filename %}
ȷʵҪÂ鷳Щ,ÓÃRequestContext and a context processor¾Í¿ÉÒÔ×Ô¶¯µÄÔØÈë±äÁ¿ÁË.

ÔÚ07-9-13£¬beck917 <beck917在gmail.com> дµÀ£º
>
> Using RequestContext and a context processor *automatically* adds these
> variables in every template, which avoids the repetitiveness of having to
> call a template tag in each template just to add some variables.
> ÎҸоõÕâ¾ä»°µÄÒâ˼ÏñÊÇ˵ִÐÐЧÂʸß,ºóÒ»¾ä˵±ÜÃâÔÚÿ¸öÄ£°åÖÐcall a template tag,Ö»ÊÇÔö¼ÓÁËһЩ±äÁ¿
>
> ÔÚ07-9-13£¬limodou <limodou在gmail.com > дµÀ£º
> >
> > On 9/13/07, beck917 <beck917在gmail.com > wrote:
> > > ˵ʵ»°ÎÒû¾õµÃrequestcontext±Ètemplate
> > > tag·½±ãÔÚÄÄ..ÓÃrequestcontextµÄµØ·½¶¼¿ÉÒÔtemplate tagʵÏÖ.
> > >
> > > ÎÒÏërequestcontextÖ÷ÒªÊÇÓÃÓÚһЩÔÚsettingÖж¨ÒåµÄ±äÁ¿(ÕâЩÐèÒªÔÚÄ£°åÖÐʹÓõıäÁ¿)
> > > ¶øtemplate tagÔòʵÏÖһЩ¸ü¸´ÔӵIJÙ×÷,±ÈÈç¶ÁÈ¡Êý¾Ý¿âÖеÄÊý¾ÝÏÔʾÔÚÄ£°åÖÐ
> > >
> > ÕâÀïµÄ¼òµ¥µÄÖ¸¿ª·¢µÄ¼òµ¥°É£¬ÎÒÊÇÕâôÀí½â¡£Ð´Ò»¸öcustom tagÒª±Èдһ¸öTEMPLATECONTEXTPROCESSORSÒªÄѵöࡣ
> >
> > --
> > I like python!
> > UliPad <>: http://code.google.com/p/ulipad/
> > My Blog: http://www.donews.net/limodou
> > _______________________________________________
> > 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/20070914/858b05a1/attachment.htm 

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

2007年09月18日 星期二 12:53

Neil(木野狐) chenrong2003在gmail.com
星期二 九月 18 12:53:12 HKT 2007

DRY

在 07-9-14,beck917<beck917在gmail.com> 写道:
> 晓得了.今天实践了下template tag,
> 原来在模板中还需要{% load template_tag_filename %}
> 确实要麻烦些,用RequestContext and a context processor就可以自动的载入变量了.
>
> 在07-9-13, beck917 <beck917在gmail.com> 写道:
> > Using RequestContext and a context processor automatically adds these
> variables in every template, which avoids the repetitiveness of having to
> call a template tag in each template just to add some variables.
> > 我感觉这句话的意思像是说执行效率高,后一句说避免在每个模板中call a template
> tag,只是增加了一些变量
> >
> >
> > 在07-9-13,limodou < limodou在gmail.com > 写道:
> >
> > > On 9/13/07, beck917 < beck917在gmail.com > wrote:
> > > > 说实话我没觉得requestcontext比template
> > > > tag方便在哪..用requestcontext的地方都可以template tag实现.
> > > >
> > > > 我想requestcontext主要是用于一些在setting中定义的变量(这些需要在模板中使用的变量)
> > > > 而template tag则实现一些更复杂的操作,比如读取数据库中的数据显示在模板中
> > > >
> > > 这里的简单的指开发的简单吧,我是这么理解。写一个custom
> tag要比写一个TEMPLATECONTEXTPROCESSORS要难得多。
> > >
> > > --
> > > I like python!
> > > UliPad <>:
> http://code.google.com/p/ulipad/
> > > My Blog: http://www.donews.net/limodou
> > > _______________________________________________
> > > 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
>

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

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

    你的回复:

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

    Zeuux © 2025

    京ICP备05028076号