0
我正在将我的旧项目升级到最新版本的python/django,并且在自定义模板标记中遇到问题。防止在django中自动转义自定义模板标记
模板标签定义:
from django import template
register = template.Library()
def my_tag(*args) -> str:
""" returns html code """
register.simple_tag(lambda *x: my_tag("hello world", *x), name='my_tag')
例标签用法:
{% my_tag "this no longer works, this autoescapes my code" %}
如何修改我的标签定义,以防止autoescaping,这样我就不必修改模板:
{% autoescape off %}{% my_tag "workaround, this doesn't autoescape html" %}{% endautoescape %}