将{%url%}传递给Django中的自定义模板标记

问题描述:

我正在开发一个需要多个参数的自定义Django模板标签。其中一个参数是一个URL。当我尝试这样做:

I'm developing a custom Django template tag that requires multiple arguments. One of those arguments is a URL. When I try to do this:

{% my_tag arg1 {% url "myview" %} arg3=5 %}

我得到以下模板语法错误:无法解析余数:'{% '从'{%'

I get the following template syntax error: Could not parse the remainder: '{%' from '{%'

如何将URL传递给自定义模板?

How can I pass a URL to a custom template?

简单的url标签支持作业。

Simple url tag supports assignment.

{% url 'myview' as my_url %}
{% my_tag arg1 my_url arg3=5 %}