将{%url%}传递给Django中的自定义模板标记 [英] Pass {% url %} to custom template tag in Django
本文介绍了将{%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 %}
这篇关于将{%url%}传递给Django中的自定义模板标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文