我正在将request.resolver_match.kwargs与django结合使用,以获取要尝试链接到的视图的url参数。如此使用
<a href="{% url 'ViewPdf' uid=request.resolver_match.kwargs.uid %}">Print this page</a>
我收到noreversematch错误。但是,如果我将它放在for循环中,它便会如此
{% for uid in request.resolver_match.kwargs.uid %}
<a href="{% url 'ViewPdf' uid=request.resolver_match.kwargs.uid %}">Print this page</a>
{% endfor %}
具有明显的副作用,即链接数量与url参数中的字符一样多。我不确定为什么它可以在for循环中工作,但不能独立运行。