Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试将{% url ..}函数的返回值缓存到带有with模板标签的变量中。
{% url ..}
with
这是我的代码: {% with path=url "show_cart" %} {% endwith %}
有了这段代码,我得到了这个异常:TemplateSyntaxError u'with' received an invalid token: u'"show_cart"'
TemplateSyntaxError
u'with' received an invalid token: u'"show_cart"'
是否可以将url函数的结果分配给变量?
url
你可以这样做。不确定此语法需要什么 Django 版本:
{% url 'view' as the_url %} {{ the_url }}
文档在这里