如何从python代码中调用django模板标记?

如何从python代码中调用django模板标记?,django,templates,tags,django-templates,Django,Templates,Tags,Django Templates,我正在编写一个非常简单的自定义标记,我想从自定义标记代码中调用django的include标记 e、 g.如何从python代码中调用django.templates.loader_标记do_include(或include)标记?我认为,您只需使用传递到模板标记的上下文来呈现模板,而不必使用include标记。例如: from django.template.loader import render_to_string @register.simple_tag(takes_context=T

我正在编写一个非常简单的自定义标记,我想从自定义标记代码中调用django的
include
标记


e、 g.如何从python代码中调用django.templates.loader_标记do_include(或include)标记?

我认为,您只需使用传递到模板标记的上下文来呈现模板,而不必使用
include
标记。例如:

from django.template.loader import render_to_string

@register.simple_tag(takes_context=True)
def my_tag(context):
    html = render_to_string("my_tag_template.html", context)
    ...
也就是说,如果您想查看include标记是如何工作的,可以在此处查看代码: