开发者

Django - replacing built-in templatetag by custom tag for a whole site without {% load .. %}

开发者 https://www.devze.com 2022-12-09 21:42 出处:网络
I want to replace the sta开发者_开发知识库ndard {% if %} template tag with a \"smart if\" custom tag from this snippet, because I don\'t want to write {% load smart_if %} every time. Also, \"smart if\

I want to replace the sta开发者_开发知识库ndard {% if %} template tag with a "smart if" custom tag from this snippet, because I don't want to write {% load smart_if %} every time. Also, "smart if" will come into core template system very soon.

I forgot where I saw a piece of code that does this. Does anyone know how to replace a built-in templatetag?


Place this somewhere you know will get run:

from django.template import add_to_builtins
add_to_builtins('mysite.myapp.templatetags.smart_if')

... while placing smart_if.py containing the smart_if code at the appropriate location. This effectively overrides the if tag with "smart if" accross the whole site.


Not a full solution to replace the "if" tag, but you can automatically load template tags.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号