如何在下拉菜单的选项标签内使用 django url?
How do I use a django url inside of an option tag in a dropdown menu?
我有一个带有两个选项的 select 标签。我希望 url 根据选项 selected 进行更改。我希望在 django 的 URLPATTERNS 中定义的 url 链接到这些选项。
我的 html:
<select name="rec-type" id="rec-type">
<!-- <a href="{% url 'transactions' rec_type='expense' %}"> -->
<option value="expense">Expense</option>
<!-- </a> -->
<!-- <a href="{% url 'transactions' rec_type='expense' %}"> -->
<option value="income">Income</option>
<!-- </a> -->
</select>
我的 url 交易是:
path('transactions/<str:rec_type>', views.transactions, name='transactions'),
<select name="rec-type" id="rec-type" onchange="location = this.value;">
<option value="{% url 'transactions' "expense" %}">Expense</option>
<option value="{% url 'transactions' "income" %}">Income</option>
</select>
这应该可以,当更改选项
时,您会转到此url
我有一个带有两个选项的 select 标签。我希望 url 根据选项 selected 进行更改。我希望在 django 的 URLPATTERNS 中定义的 url 链接到这些选项。 我的 html:
<select name="rec-type" id="rec-type">
<!-- <a href="{% url 'transactions' rec_type='expense' %}"> -->
<option value="expense">Expense</option>
<!-- </a> -->
<!-- <a href="{% url 'transactions' rec_type='expense' %}"> -->
<option value="income">Income</option>
<!-- </a> -->
</select>
我的 url 交易是:
path('transactions/<str:rec_type>', views.transactions, name='transactions'),
<select name="rec-type" id="rec-type" onchange="location = this.value;">
<option value="{% url 'transactions' "expense" %}">Expense</option>
<option value="{% url 'transactions' "income" %}">Income</option>
</select>
这应该可以,当更改选项
时,您会转到此url