Django url在多行模板中的参数[重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

我的模板中有这种类型的网址:

<a href="{% url 'company-detail' region=ownership.company.city.province.region.slug province=ownership.company.city.province.slug city=ownership.company.city.slug company=ownership.company.slug %}">

也就是说,正如你所看到的,可怕的长。

有多种方法可以在多行中做同样的事情?

像这样的东西:

<a href="{% url 'company-detail'
            region=ownership.company.city.province.region.slug
            province=ownership.company.city.province.slug
            city=ownership.company.city.slug
            company=ownership.company.slug %}">
django django-templates django-urls
1个回答
1
投票
{% with region=ownership.company.city.province.region.slug province=ownership.company.city.province.slug city=ownership.company.city.slug company=ownership.company.slug %}
<a href="{% url 'company-detail' region province city company %}">
{% endwith %}

你可以这样做

© www.soinside.com 2019 - 2024. All rights reserved.