目前,我有近两个完全一样的模板,它们使用相同的Django的形式,但只有1个参数的变化以这两种形式是操作方法,那就是如何重用Django模板?
Django的形式
class DropDownMenu(forms.Form):
week = forms.ChoiceField(choices=[(x,x) for x in range(1,53)]
year = forms.ChoiceField(choices=[(x,x) for x in range(2015,2030)]
模板1
<form id="search_dates" method="POST" action="/tickets_per_day/">
<div class="row">
<div style="display:inline-block">
<h6>Select year</h6>
<select name="select_year">
<option value={{form.year}}></option>
</select>
</div>
<button type="submit">Search</button>
</div>
</form>
模板2
<form id="search_dates" method="POST" action="/quantitative_analysis/">
<div class="row">
<div style="display:inline-block">
<h6>Select year</h6>
<select name="select_year">
<option value={{form.year}}></option>
</select>
</div>
<button type="submit">Search</button>
</div>
</form>
是改变是操作方法,所以我想知道是否有可能重新使用该变化仅在操作方法一个模板的唯一的事情。如果可能的话,你能帮我解码吗?
我检查了这个问题django - how to reuse a template for nearly identical models?但我没有在这里使用任何模型与我的模板。
您可以从视图集本身发送操作属性,然后您可以重新使用模板 – Robert