且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

带有可配置模板的 Django 包含标签

更新时间:2022-06-16 10:47:22

inclusion_tag 装饰器只是一种快捷方式——它是一种简单的方式来呈现具有特定上下文的特定模板.一旦你想摆脱它,它就不再能帮助你了.但这只是意味着您必须按照文档中的说明长时间编写标签,并将所需的模板作为参数传递.

The inclusion_tag decorator is just a shortcut - it's meant as a simple way of rendering a specific template with a specific context. As soon as you want to move outside of that, it can no longer help you. But that just means you'll have to write the tag the long way, as explained in the documentation, and pass the template you want as a parameter.