我有一个用模板渲染的输入字段,如下所示:
<div class="field"> {{ form.city }} </div>
呈现为:
<div class="field"> <input id="id_city" type="text" name="city" maxlength="100" /> </div>
现在,假设我想向autocomplete="off"呈现的输入元素添加一个属性,我该怎么做?还是onclick="xyz()"或者class="my-special-css-class"?
autocomplete="off"
onclick="xyz()"
class="my-special-css-class"?
city = forms.CharField(widget=forms.TextInput(attrs={'autocomplete':'off'}))