就像标题所说的那样,我将变量传递给名为' old_link'的django模板。就这样:
{% if type_disp == 'charts' %}<li class="active">{% endif %}<a href="{% url 'matching:analytics' action=action type_disp='charts' %}?{{old_link}}" class="text-primary"><i class="fa fa-fw fa-bolt"></i>Charts</a></li>
{% if type_disp == 'tables' %}<li class="active">{% endif %}<a href="{% url 'matching:analytics' action=action type_disp='tables' %}?{{old_link}}" class="text-primary"><i class="fa fa-fw fa-calendar"></i>Table</a></li>
&#39; old_link&#39;应该将变量添加到url的末尾,但它一直给我错误的链接。为了测试它,我还将变量发布在模板的另一部分中,以查看它返回的内容。您可以在&#39;公司数量之上看到正确的价值。下图中的部分。它在表格中发布的值以及它在网址中发布的值完全不同,我不确定原因。
在下图中,您可以看到应该应用变量的网址部分,它显示&#39; http://127.0.0.1 ...&#39;而不是&#39; year_min ...&#39;它应该的价值。
<div class="item col-md-8 col-xs-12">
<div class="panel panel-default">
<div class="panel-body">
<div class="row">
<div class="col-xs-6">
<h4 class="text-headline margin-none">{{company_amount}}</h4>
<p class="text-light">
<i class="fa fa-circle-o text-success fa-fw"></i> Total Funding
</p>
</div>
<div class="col-xs-6">
<h4 class="text-headline margin-none">{{old_link}}</h4>
<p class="text-light">
<i class="fa fa-circle-o text-danger fa-fw"></i> Number of
Companies
</p>
</div>
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">{{title}}</h4>
</div>
{% if type_disp == 'charts' %}
{% with form=entity_choice_form %}
{% include 'common/form-alert.html' %}
{% endwith %}
<div class="panel-body">
{% if action == 'industry-compare' %}
<div id="industry-compare"></div>
{% elif action == 'insurtech-total' %}
<div id="insurtech-total"></div>
{% elif action == 'industry-concentration' %}
<div id="industry-concentration"></div>
{% elif action == 'new-entrants' %}
<div id="new-entrants"></div>
{% endif %}
{% elif type_disp == 'tables' %}
<div class="panel-body">
{% render_table Table_Values %}
{% endif %}
</div>
</div>
</div>
<div class="col-md-2">
<ul class="nav nav-pills nav-stacked">
{% if type_disp == 'charts' %}<li class="active">{% endif %}<a href="{% url 'matching:analytics' action=action type_disp='charts' %}?{{old_link}}" class="text-primary"><i class="fa fa-fw fa-bolt"></i>Charts</a></li>
{% if type_disp == 'tables' %}<li class="active">{% endif %}<a href="{% url 'matching:analytics' action=action type_disp='tables' %}?{{old_link}}" class="text-primary"><i class="fa fa-fw fa-calendar"></i>Table</a></li>
</ul>
</div>
第一次调用变量是在&#39; h4&#39;然后又在导航丸中调用了它。以下是我在视图中传递变量的方法:
'old_link':referer1,
我已经验证过&#39; refer1&#39;有我想要的价值。我如何确保变量在两个地方都是相同的,为什么它首先是不同的?
答案 0 :(得分:0)
试试这个
{% if type_disp == 'charts' %}<li class="active">{% endif %}<a href="{% url 'matching:analytics' action=action type_disp='charts' %}?old_link={{old_link}}" class="text-primary"><i class="fa fa-fw fa-bolt"></i>Charts</a></li>
您必须将key =值放入网址(?old_link = {{old_link}})